diff --git a/seeker/report.txt b/seeker/report.txt index 2ed890a8..40d8526f 100644 --- a/seeker/report.txt +++ b/seeker/report.txt @@ -1,3 +1,65 @@ +-------------------------------------------------------------------------------- + 2024-08-19 17:13:16.613524 +-------------------------------------------------------------------------------- + On branch main +Your branch is up to date with 'origin/main'. + +Changes not staged for commit: + (use "git add/rm ..." to update what will be committed) + (use "git restore ..." to discard changes in working directory) + deleted: snippet/.bash_profile + deleted: snippet/.bashrc + deleted: snippet/.zshrc + deleted: snippet/Controller.java + deleted: snippet/CudaMemoryMonitor.py + deleted: snippet/Dockerfile + deleted: snippet/Employee.java + deleted: snippet/EmployeeController.java + deleted: snippet/EmployeeRepository.java + deleted: snippet/EmployeeThymeleafController.java + deleted: snippet/GlobalExceptionHandler.java + deleted: snippet/Interrrupts.java + deleted: snippet/Patient.java + deleted: snippet/PatientControllerTest.java + deleted: snippet/Repositories.java + deleted: snippet/SwaggerConfig.java + deleted: snippet/TimeMonitor.py + deleted: snippet/accessor_methods.go + deleted: snippet/createWorktrees.sh + deleted: snippet/ddwrt_load_nsfw_blacklist.sh + deleted: snippet/file.py + deleted: snippet/game.py + deleted: snippet/game2.py + deleted: snippet/instance_init.go + deleted: snippet/l3min.py + deleted: snippet/mapreduce.py + deleted: snippet/modal_fasthtml.py + deleted: snippet/module_6_1.py + deleted: snippet/pkgx-wrapper + deleted: snippet/python-programming.py + deleted: snippet/reflection.go + deleted: snippet/reset-author-of-multiple-commits.bash + deleted: snippet/ros2_stream_chunks.py + deleted: snippet/sim.py + deleted: snippet/twenty_eight.java + deleted: snippet/upssched-cmd + +Untracked files: + (use "git add ..." to include in what will be committed) + snippet/archive-all.sh + snippet/clone_git.sh + snippet/dask_custom_cache.py + snippet/dask_lru_cache.py + snippet/execute_as_infant.sh + snippet/init.sh + snippet/lmc_emulator.py + snippet/main.go + snippet/txtai-stocks.py + snippet/update_discord + snippet/worklog.py + +no changes added to commit (use "git add" and/or "git commit -a") + -------------------------------------------------------------------------------- 2024-08-16 17:11:40.858028 -------------------------------------------------------------------------------- diff --git a/seeker/snippet/.bash_profile b/seeker/snippet/.bash_profile deleted file mode 100644 index 9dc97e16..00000000 --- a/seeker/snippet/.bash_profile +++ /dev/null @@ -1,5 +0,0 @@ -#date: 2024-08-16T16:56:48Z -#url: https://api.github.com/gists/1f64e5cb4a7d8b981139b173e856731d -#owner: https://api.github.com/users/SAURABHMISHRA55 - -export JAVA_HOME=/path/to/java \ No newline at end of file diff --git a/seeker/snippet/.bashrc b/seeker/snippet/.bashrc deleted file mode 100644 index 08bcdcba..00000000 --- a/seeker/snippet/.bashrc +++ /dev/null @@ -1,6 +0,0 @@ -#date: 2024-08-16T16:56:48Z -#url: https://api.github.com/gists/1f64e5cb4a7d8b981139b173e856731d -#owner: https://api.github.com/users/SAURABHMISHRA55 - -JAVA_Home=/path/to/java -export JAVA_HOME \ No newline at end of file diff --git a/seeker/snippet/.zshrc b/seeker/snippet/.zshrc deleted file mode 100644 index afc2cdb7..00000000 --- a/seeker/snippet/.zshrc +++ /dev/null @@ -1,56 +0,0 @@ -#date: 2024-08-15T16:53:32Z -#url: https://api.github.com/gists/41526c2957513e6392555309dd435c4c -#owner: https://api.github.com/users/ppcamp - - -# thanks to https://github.com/junegunn/fzf/issues/2789#issuecomment-2196524694 -rgfzf() { - if [ ! "$#" -gt 0 ]; then echo "Need a string to search for!"; return 1; fi - - rg --color=always --line-number --no-heading --smart-case "#{*:-}" \ - | fzf -d':' --ansi \ - --preview "bat -p --color=always {1} --highlight-line{2}" \ - --preview-window ~8,+{2}-5 \ - | awk -F':' '{ print $1 ":" $2 }' \ - | xargs -r -I {} code -g {} -} - -# fif shows the file that matched with the search, and using fzf -# allows user to see it, similar behavior to 'telescope' nvim ext. -# -# You can also open vscode in the selected line, in the end -# -# thanks to https://www.reddit.com/r/commandline/comments/fu6zzp/search_file_content_with_fzf/ -# thanks to https://github.com/junegunn/fzf/issues/2789#issuecomment-2196524694 -fif() { - if [ ! "$#" -gt 0 ]; then echo "Need a string to search for!"; return 1; fi - - rg --line-number --no-heading --smart-case "#{*:-}" \ - | awk -F: '{ printf "\033[1;32m%s\033[0m:\033[1;34m%s\033[0m\n", $1, $2 }' \ - | fzf -d':' --ansi \ - --preview "bat -p --color=always {1} --highlight-line{2}" \ - --preview-window ~8,+{2}-5 \ - | xargs -r -I {} code -g {} -} - - -# Define the widget to execute your functino -# thanks to https://superuser.com/a/1564526 -# -# Bind Ctrl+X to open a search box that will allow user to input and use it in a function -function inputFif_widget { - local REPLY - autoload -Uz read-from-minibuffer - - # Create a sub-prompt, pre-populated with the current contents of the command line - read-from-minibuffer 'Keywords to search: ' $LBUFFER $RBUFFER - - # Use the modified input to search and update comand line with it - LBUFFER=$(echo "$(fif $REPLY)") - RBUFFER='' - - # Put some additional text bellow command line - # zle -M "Equivalent command: fif '$REPLY'" -} -zle -N inputFif_widget -bindkey '^X' 'inputFif_widget' # bind Ctrl+X to search \ No newline at end of file diff --git a/seeker/snippet/Controller.java b/seeker/snippet/Controller.java deleted file mode 100644 index a981ebb6..00000000 --- a/seeker/snippet/Controller.java +++ /dev/null @@ -1,37 +0,0 @@ -//date: 2024-08-16T16:52:44Z -//url: https://api.github.com/gists/2937ebacefc46368256725d190b1b4bc -//owner: https://api.github.com/users/Raja696969 - -@RestController -@RequestMapping("/api/patients") -public class PatientController { - @Autowired - private PatientRepository patientRepository; - - @PostMapping - public Patient registerPatient(@RequestBody Patient patient) { - return patientRepository.save(patient); - } - - @GetMapping("/{id}") - public Optional getPatient(@PathVariable Long id) { - return patientRepository.findById(id); - } -} - -@RestController -@RequestMapping("/api/appointments") -public class AppointmentController { - @Autowired - private AppointmentRepository appointmentRepository; - - @PostMapping - public Appointment bookAppointment(@RequestBody Appointment appointment) { - return appointmentRepository.save(appointment); - } - - @GetMapping("/patient/{patientId}") - public List getAppointmentsByPatient(@PathVariable Long patientId) { - return appointmentRepository.findByPatientId(patientId); - } -} diff --git a/seeker/snippet/CudaMemoryMonitor.py b/seeker/snippet/CudaMemoryMonitor.py deleted file mode 100644 index 87523b97..00000000 --- a/seeker/snippet/CudaMemoryMonitor.py +++ /dev/null @@ -1,124 +0,0 @@ -#date: 2024-08-16T16:48:57Z -#url: https://api.github.com/gists/c394b2300e6bd57e0ca1a22478072941 -#owner: https://api.github.com/users/kabouzeid - -# Copyright (c) Karim Abou Zeid - -from typing import Any - -import lightning.pytorch as pl -import torch -from lightning.pytorch.callbacks.callback import Callback -from lightning.pytorch.utilities.exceptions import MisconfigurationException -from lightning.pytorch.utilities.types import STEP_OUTPUT -from typing_extensions import override - - -class CudaMemoryMonitor(Callback): - def __init__(self, name="cuda_memory", prog_bar=True) -> None: - super().__init__() - self.name = name - self.prog_bar = prog_bar - - @override - def setup( - self, - trainer: "pl.Trainer", - pl_module: "pl.LightningModule", - stage: str, - ) -> None: - if stage != "fit": - return - - if not trainer.loggers: - raise MisconfigurationException( - "Cannot use `GpuMemoryMonitor` callback with `Trainer(logger=False)`." - ) - - device = trainer.strategy.root_device - if not device.type == "cuda": - raise MisconfigurationException( - f"Cannot use `GpuMemoryMonitor` callback with {device.type} device." - ) - - def _get_and_log_device_stats( - self, trainer: "pl.Trainer", pl_module: "pl.LightningModule", key: str - ) -> None: - max_mem_gibi = torch.cuda.max_memory_allocated(trainer.strategy.root_device) / ( - 2**30 - ) - pl_module.log( - f"{key}_{self.name}", - max_mem_gibi, - on_step=True, - on_epoch=False, - reduce_fx=torch.max, - prog_bar=self.prog_bar, - ) - - @override - def on_train_batch_start( - self, - trainer: "pl.Trainer", - pl_module: "pl.LightningModule", - batch: Any, - batch_idx: int, - ) -> None: - torch.cuda.reset_peak_memory_stats() - - @override - def on_train_batch_end( - self, - trainer: "pl.Trainer", - pl_module: "pl.LightningModule", - outputs: STEP_OUTPUT, - batch: Any, - batch_idx: int, - ) -> None: - self._get_and_log_device_stats(trainer, pl_module, "train") - - @override - def on_validation_batch_start( - self, - trainer: "pl.Trainer", - pl_module: "pl.LightningModule", - batch: Any, - batch_idx: int, - dataloader_idx: int = 0, - ) -> None: - torch.cuda.reset_peak_memory_stats() - - @override - def on_validation_batch_end( - self, - trainer: "pl.Trainer", - pl_module: "pl.LightningModule", - outputs: STEP_OUTPUT, - batch: Any, - batch_idx: int, - dataloader_idx: int = 0, - ) -> None: - self._get_and_log_device_stats(trainer, pl_module, "validation") - - @override - def on_test_batch_start( - self, - trainer: "pl.Trainer", - pl_module: "pl.LightningModule", - batch: Any, - batch_idx: int, - dataloader_idx: int = 0, - ) -> None: - torch.cuda.reset_peak_memory_stats() - - @override - def on_test_batch_end( - self, - trainer: "pl.Trainer", - pl_module: "pl.LightningModule", - outputs: STEP_OUTPUT, - batch: Any, - batch_idx: int, - dataloader_idx: int = 0, - ) -> None: - self._get_and_log_device_stats(trainer, pl_module, "test") diff --git a/seeker/snippet/Dockerfile b/seeker/snippet/Dockerfile deleted file mode 100644 index 3afca4f3..00000000 --- a/seeker/snippet/Dockerfile +++ /dev/null @@ -1,43 +0,0 @@ -#date: 2024-08-15T17:09:30Z -#url: https://api.github.com/gists/f7dccfda0aa5a7c10226ae4f460ead4c -#owner: https://api.github.com/users/ilynne - -FROM ruby:3.0-bullseye - -ENV BUNDLER_VERSION=2 - -RUN apt-get update && apt-get install -y \ - build-essential \ - nodejs \ - npm \ - yarn \ - python \ - libpq-dev \ - && gem install bundler \ - && mkdir -p /app - -WORKDIR /app - -# COPY Gemfile Gemfile.lock ./ -# RUN bundle config build.nokogiri --use-system-libraries -# RUN bundle check || bundle install - -# COPY package.json yarn.lock ./ -# RUN yarn install --check-files - -COPY . ./ - -RUN curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.34.0/install.sh | bash -RUN curl -fsSL https://raw.githubusercontent.com/tophat/yvm/master/scripts/install.sh | bash -CMD ["nvm install 16.20.0"] -CMD ["nvm use 16.20.0"] -CMD ["npm install webpack-dev-server"] -CMD ["yvm use 1.22.22"] - -# ENTRYPOINT ["./entrypoints/docker-entrypoint.sh"] - -# EXPOSE 3000 - -# CMD ["/bin/bash"] - -# CMD ["bundle", "exec", "rails", "server", "-b", "0.0.0.0"] diff --git a/seeker/snippet/Employee.java b/seeker/snippet/Employee.java deleted file mode 100644 index f1532676..00000000 --- a/seeker/snippet/Employee.java +++ /dev/null @@ -1,31 +0,0 @@ -//date: 2024-08-16T16:37:12Z -//url: https://api.github.com/gists/84cffe6e32f08c7d08241dfeba3ec697 -//owner: https://api.github.com/users/Raja696969 - -package com.example.employeemanagement.model; - -import javax.persistence.*; -import javax.validation.constraints.Email; -import javax.validation.constraints.NotBlank; -import javax.validation.constraints.Size; - -@Entity -public class Employee { - - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - private Long id; - - @NotBlank(message = "Name is mandatory") - @Size(min = 2, max = 100, message = "Name must be between 2 and 100 characters") - private String name; - - @NotBlank(message = "Email is mandatory") - @Email(message = "Email should be valid") - private String email; - - @NotBlank(message = "Department is mandatory") - private String department; - - // Getters and Setters -} diff --git a/seeker/snippet/EmployeeController.java b/seeker/snippet/EmployeeController.java deleted file mode 100644 index e743a876..00000000 --- a/seeker/snippet/EmployeeController.java +++ /dev/null @@ -1,73 +0,0 @@ -//date: 2024-08-16T16:37:12Z -//url: https://api.github.com/gists/84cffe6e32f08c7d08241dfeba3ec697 -//owner: https://api.github.com/users/Raja696969 - -package com.example.employeemanagement.controller; - -import com.example.employeemanagement.model.Employee; -import com.example.employeemanagement.repository.EmployeeRepository; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.ResponseEntity; -import org.springframework.validation.BindingResult; -import org.springframework.web.bind.annotation.*; - -import javax.validation.Valid; -import java.util.List; - -@RestController -@RequestMapping("/api/employees") -public class EmployeeController { - - @Autowired - private EmployeeRepository employeeRepository; - - // Create Employee - @PostMapping - public ResponseEntity createEmployee(@Valid @RequestBody Employee employee, BindingResult result) { - if (result.hasErrors()) { - return ResponseEntity.badRequest().body(result.getAllErrors()); - } - return ResponseEntity.ok(employeeRepository.save(employee)); - } - - // Get all Employees - @GetMapping - public List getAllEmployees() { - return employeeRepository.findAll(); - } - - // Get Employee by ID - @GetMapping("/{id}") - public ResponseEntity getEmployeeById(@PathVariable Long id) { - return employeeRepository.findById(id) - .map(ResponseEntity::ok) - .orElse(ResponseEntity.notFound().build()); - } - - // Update Employee - @PutMapping("/{id}") - public ResponseEntity updateEmployee(@PathVariable Long id, @Valid @RequestBody Employee employee, BindingResult result) { - if (result.hasErrors()) { - return ResponseEntity.badRequest().body(result.getAllErrors()); - } - return employeeRepository.findById(id) - .map(existingEmployee -> { - existingEmployee.setName(employee.getName()); - existingEmployee.setEmail(employee.getEmail()); - existingEmployee.setDepartment(employee.getDepartment()); - return ResponseEntity.ok(employeeRepository.save(existingEmployee)); - }) - .orElse(ResponseEntity.notFound().build()); - } - - // Delete Employee - @DeleteMapping("/{id}") - public ResponseEntity deleteEmployee(@PathVariable Long id) { - return employeeRepository.findById(id) - .map(employee -> { - employeeRepository.delete(employee); - return ResponseEntity.ok().build(); - }) - .orElse(ResponseEntity.notFound().build()); - } -} diff --git a/seeker/snippet/EmployeeRepository.java b/seeker/snippet/EmployeeRepository.java deleted file mode 100644 index 1d49a648..00000000 --- a/seeker/snippet/EmployeeRepository.java +++ /dev/null @@ -1,13 +0,0 @@ -//date: 2024-08-16T16:37:12Z -//url: https://api.github.com/gists/84cffe6e32f08c7d08241dfeba3ec697 -//owner: https://api.github.com/users/Raja696969 - -package com.example.employeemanagement.repository; - -import com.example.employeemanagement.model.Employee; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.stereotype.Repository; - -@Repository -public interface EmployeeRepository extends JpaRepository { -} diff --git a/seeker/snippet/EmployeeThymeleafController.java b/seeker/snippet/EmployeeThymeleafController.java deleted file mode 100644 index 4ee71f33..00000000 --- a/seeker/snippet/EmployeeThymeleafController.java +++ /dev/null @@ -1,54 +0,0 @@ -//date: 2024-08-16T16:37:12Z -//url: https://api.github.com/gists/84cffe6e32f08c7d08241dfeba3ec697 -//owner: https://api.github.com/users/Raja696969 - -package com.example.employeemanagement.controller; - -import com.example.employeemanagement.model.Employee; -import com.example.employeemanagement.repository.EmployeeRepository; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Controller; -import org.springframework.ui.Model; -import org.springframework.web.bind.annotation.*; - -@Controller -@RequestMapping("/employees") -public class EmployeeThymeleafController { - - @Autowired - private EmployeeRepository employeeRepository; - - @GetMapping - public String listEmployees(Model model) { - model.addAttribute("employees", employeeRepository.findAll()); - return "index"; - } - - @GetMapping("/add") - public String showAddEmployeeForm(Model model) { - model.addAttribute("employee", new Employee()); - return "add-employee"; - } - - @PostMapping - public String addEmployee(Employee employee) { - employeeRepository.save(employee); - return "redirect:/employees"; - } - - @GetMapping("/edit/{id}") - public String showUpdateForm(@PathVariable Long id, Model model) { - Employee employee = employeeRepository.findById(id) - .orElseThrow(() -> new IllegalArgumentException("Invalid employee Id:" + id)); - model.addAttribute("employee", employee); - return "add-employee"; - } - - @GetMapping("/delete/{id}") - public String deleteEmployee(@PathVariable Long id) { - Employee employee = employeeRepository.findById(id) - .orElseThrow(() -> new IllegalArgumentException("Invalid employee Id:" + id)); - employeeRepository.delete(employee); - return "redirect:/employees"; - } -} diff --git a/seeker/snippet/GlobalExceptionHandler.java b/seeker/snippet/GlobalExceptionHandler.java deleted file mode 100644 index 14957f24..00000000 --- a/seeker/snippet/GlobalExceptionHandler.java +++ /dev/null @@ -1,19 +0,0 @@ -//date: 2024-08-16T16:37:12Z -//url: https://api.github.com/gists/84cffe6e32f08c7d08241dfeba3ec697 -//owner: https://api.github.com/users/Raja696969 - -package com.example.employeemanagement.exception; - -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.ControllerAdvice; -import org.springframework.web.bind.annotation.ExceptionHandler; - -@ControllerAdvice -public class GlobalExceptionHandler { - - @ExceptionHandler(Exception.class) - public ResponseEntity handleException(Exception e) { - return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(e.getMessage()); - } -} diff --git a/seeker/snippet/Interrrupts.java b/seeker/snippet/Interrrupts.java deleted file mode 100644 index efc04752..00000000 --- a/seeker/snippet/Interrrupts.java +++ /dev/null @@ -1,51 +0,0 @@ -//date: 2024-08-15T16:45:57Z -//url: https://api.github.com/gists/618d6af1eb71663d59b2c2d6e35cbc5f -//owner: https://api.github.com/users/ShobharaniPotru - - class Interrrupts implements Runnable -{ - Thread t; - public Interrrupts() - { - t = new Thread(this); - System.out.println("Executing" + t.getName()); - t.start(); - if (!t.interrupted()) - { - // Interrupts this thread. - t.interrupt(); - } - // block until other threads finish - try - { - t.join(); - } - catch (InterruptedException e) - { - - } - } - public void run() - { - try - { - while (true) - { - Thread.sleep(1000); - } - } - catch (InterruptedException e) - { - - System.out.println(t.getName() + "interrupted:"); - System.out.println(e.toString() + "\n"); - } - } -} -public class ThreadDE -{ - public static void main(String[] args) { - new Interrrupts(); - new Interrrupts(); - } -} \ No newline at end of file diff --git a/seeker/snippet/Patient.java b/seeker/snippet/Patient.java deleted file mode 100644 index cdb39988..00000000 --- a/seeker/snippet/Patient.java +++ /dev/null @@ -1,56 +0,0 @@ -//date: 2024-08-16T16:52:44Z -//url: https://api.github.com/gists/2937ebacefc46368256725d190b1b4bc -//owner: https://api.github.com/users/Raja696969 - -// Patient.java -@Entity -public class Patient { - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - private Long id; - private String name; - private String contactDetails; - private String medicalHistory; - // Getters and Setters -} - -// Doctor.java -@Entity -public class Doctor { - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - private Long id; - private String name; - private String specialization; - // Getters and Setters -} - -// Appointment.java -@Entity -public class Appointment { - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - private Long id; - private Date appointmentDate; - - @ManyToOne - private Patient patient; - - @ManyToOne - private Doctor doctor; - // Getters and Setters -} - -// Medication.java -@Entity -public class Medication { - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - private Long id; - private String name; - private String dosage; - - @ManyToOne - private Patient patient; - // Getters and Setters -} diff --git a/seeker/snippet/PatientControllerTest.java b/seeker/snippet/PatientControllerTest.java deleted file mode 100644 index cb4ef743..00000000 --- a/seeker/snippet/PatientControllerTest.java +++ /dev/null @@ -1,18 +0,0 @@ -//date: 2024-08-16T16:52:44Z -//url: https://api.github.com/gists/2937ebacefc46368256725d190b1b4bc -//owner: https://api.github.com/users/Raja696969 - -@SpringBootTest -public class PatientControllerTest { - - @Autowired - private MockMvc mockMvc; - - @Test - public void testRegisterPatient() throws Exception { - mockMvc.perform(post("/api/patients") - .contentType(MediaType.APPLICATION_JSON) - .content("{\"name\": \"John Doe\", \"contactDetails\": \"1234567890\", \"medicalHistory\": \"None\"}")) - .andExpect(status().isOk()); - } -} diff --git a/seeker/snippet/Repositories.java b/seeker/snippet/Repositories.java deleted file mode 100644 index 9b310d08..00000000 --- a/seeker/snippet/Repositories.java +++ /dev/null @@ -1,11 +0,0 @@ -//date: 2024-08-16T16:52:44Z -//url: https://api.github.com/gists/2937ebacefc46368256725d190b1b4bc -//owner: https://api.github.com/users/Raja696969 - -public interface PatientRepository extends JpaRepository {} - -public interface DoctorRepository extends JpaRepository {} - -public interface AppointmentRepository extends JpaRepository {} - -public interface MedicationRepository extends JpaRepository {} diff --git a/seeker/snippet/SwaggerConfig.java b/seeker/snippet/SwaggerConfig.java deleted file mode 100644 index 8159dae5..00000000 --- a/seeker/snippet/SwaggerConfig.java +++ /dev/null @@ -1,27 +0,0 @@ -//date: 2024-08-16T16:37:12Z -//url: https://api.github.com/gists/84cffe6e32f08c7d08241dfeba3ec697 -//owner: https://api.github.com/users/Raja696969 - -package com.example.employeemanagement.config; - -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import springfox.documentation.builders.PathSelectors; -import springfox.documentation.builders.RequestHandlerSelectors; -import springfox.documentation.spi.DocumentationType; -import springfox.documentation.spring.web.plugins.Docket; -import springfox.documentation.swagger2.annotations.EnableSwagger2; - -@Configuration -@EnableSwagger2 -public class SwaggerConfig { - - @Bean - public Docket api() { - return new Docket(DocumentationType.SWAGGER_2) - .select() - .apis(RequestHandlerSelectors.any()) - .paths(PathSelectors.any()) - .build(); - } -} diff --git a/seeker/snippet/TimeMonitor.py b/seeker/snippet/TimeMonitor.py deleted file mode 100644 index f69bf2c3..00000000 --- a/seeker/snippet/TimeMonitor.py +++ /dev/null @@ -1,57 +0,0 @@ -#date: 2024-08-16T16:48:18Z -#url: https://api.github.com/gists/a1e2432a51b34a106001db92e332a94b -#owner: https://api.github.com/users/kabouzeid - -# Copyright (c) Karim Abou Zeid - -from typing import Any - -import lightning.pytorch as pl -from lightning.pytorch.callbacks.callback import Callback -from lightning.pytorch.utilities.exceptions import MisconfigurationException -from lightning.pytorch.utilities.types import STEP_OUTPUT -from typing_extensions import override - - -class TimeMonitor(Callback): - def __init__(self, prog_bar=True) -> None: - super().__init__() - self.prog_bar = prog_bar - - @override - def setup( - self, - trainer: "pl.Trainer", - pl_module: "pl.LightningModule", - stage: str, - ) -> None: - if stage != "fit": - return - - if not isinstance(trainer.profiler, pl.profilers.SimpleProfiler): - raise MisconfigurationException( - "Cannot use `TimeMonitor` callback without `Trainer(profiler='simple')`." - ) - - @override - def on_train_batch_end( - self, - trainer: "pl.Trainer", - pl_module: "pl.LightningModule", - outputs: STEP_OUTPUT, - batch: Any, - batch_idx: int, - ) -> None: - pl_module.log_dict( - { - "batch_time": trainer.profiler.recorded_durations["run_training_batch"][ - -1 - ], - "data_time": trainer.profiler.recorded_durations[ - "[_TrainingEpochLoop].train_dataloader_next" - ][-1], - }, - on_step=True, - on_epoch=False, - prog_bar=True, - ) diff --git a/seeker/snippet/accessor_methods.go b/seeker/snippet/accessor_methods.go deleted file mode 100644 index ce97a331..00000000 --- a/seeker/snippet/accessor_methods.go +++ /dev/null @@ -1,11 +0,0 @@ -//date: 2024-08-16T17:08:59Z -//url: https://api.github.com/gists/db97c2388e335f6f542a874fba4745b8 -//owner: https://api.github.com/users/hariso - -func (p *Instance) SetStatus(s Status) { - p.status.Store(&s) -} - -func (p *Instance) GetStatus() Status { - return *p.status.Load() -} \ No newline at end of file diff --git a/seeker/snippet/archive-all.sh b/seeker/snippet/archive-all.sh new file mode 100644 index 00000000..68b6eeb6 --- /dev/null +++ b/seeker/snippet/archive-all.sh @@ -0,0 +1,108 @@ +#date: 2024-08-19T16:53:21Z +#url: https://api.github.com/gists/3560f17bc52bede36670527a00b14f88 +#owner: https://api.github.com/users/OwOchle + +#! /bin/bash + +cleanup() { + echo "> cleaning up"; + rm -rf $1; + git checkout $BEFORE_CHECKOUT; +} + +warn() { + echo -e "\e[1;33m$1\e[0m" +} + +exit_no_cleanup() { + echo -e "\e[31m$1\e[0m" > /dev/stderr; + exit 1; +} + +exit_cleanup() { + echo -e "\e[31m$1\e[0m" > /dev/stderr; + cleanup $2; + exit 1; +} + +ask_confirm() { + read -p "$1? (y/N) " -n 1 -r + echo "" + if [[ ! $REPLY =~ ^[Yy]$ ]] + then + echo "aborting" + exit 1 + fi +} + +echo "===== WARNING =====" +echo "In order to ensure correct version of submodules, this utility will checkout the provided revision" +ask_confirm "Continue" + +BEFORE_CHECKOUT=$(git rev-parse --short HEAD) + +if ! git status > /dev/null 2> /dev/null; +then + exit_no_cleanup "> not a git repository"; +fi + + +if [ -n "$2" ]; +then + echo "> checking existence of revision $2" + + if ! git log "$2" > /dev/null 2> /dev/null; + then + exit_no_cleanup "> revision $2 not found" + fi + + COMMIT=$2 +else + warn "> no revision provided, defaulting to HEAD" + COMMIT="HEAD" +fi + +echo "> checking out revision" +git checkout "$COMMIT" + +echo "> updating submodules" +git submodule update --init --recursive + +echo "> creating root archive" +TEMPORARY=$(mktemp -d) + + +if ! git archive --prefix "/" --format "tar" --output "$TEMPORARY/repo-output.tar" "$COMMIT" ; +then + echo "> error archiving base repo" > /dev/stderr + cleanup "$TEMPORARY" + exit 1 +fi + +echo "> creating submodule archives" + +GIT_SUBCOMMAND='git archive --prefix=/$path/ --format tar HEAD --output' + +if ! git submodule foreach --recursive "$GIT_SUBCOMMAND $TEMPORARY/repo-output-sub-\$sha1.tar"; +then + exit_cleanup "> error while archiving submodules" $TEMPORARY +fi + +ls "$TEMPORARY" + +if [[ $(find "$TEMPORARY" -iname "repo-output-sub*.tar" | wc -l) != 0 ]]; +then + echo "> combining tars" + tar --concatenate --file "$TEMPORARY/repo-output.tar" "$TEMPORARY"/repo-output-sub*.tar +fi + +if [ "$1" = "" ] || [ "$1" = "-" ]; +then + OUTPUT="$(basename "$(git rev-parse --show-toplevel)").tar.zstd" +else + OUTPUT="$1" +fi + +echo "> zstd compression to $OUTPUT" +zstd -q -f -T0 "$TEMPORARY/repo-output.tar" -o "$OUTPUT" +cleanup "$TEMPORARY" \ No newline at end of file diff --git a/seeker/snippet/clone_git.sh b/seeker/snippet/clone_git.sh new file mode 100644 index 00000000..e107bde2 --- /dev/null +++ b/seeker/snippet/clone_git.sh @@ -0,0 +1,41 @@ +#date: 2024-08-19T16:52:13Z +#url: https://api.github.com/gists/d048ff367e8ca0e05f93cb55f8785b98 +#owner: https://api.github.com/users/damaon + +gh_print() { + local github_url="$1" + local repo_name=$(basename "$github_url" .git) + local tmp_dir="/tmp/$repo_name" + + # Clone the repository + if git clone "$github_url" "$tmp_dir" > /dev/null 2>&1; then + : # Silent success + else + echo "Failed to clone repository" + return 1 + fi + + # Define the tree_with_content function + tree_with_content() { + local dir="${1:-.}" # Use current directory if no argument is provided + local base_dir="$(cd "$dir" && pwd)" + find "$dir" -type f -not -path '*/\.git/*' | while read -r file; do + local relative_path="${file#$base_dir/}" + echo "[$relative_path]" + # Check if the file is a text file + if file -b --mime-type "$file" | grep -q "^text/"; then + cat "$file" + else + echo "(Not a text file)" + fi + echo "" + done + } + + # Call tree_with_content on the cloned repository + tree_with_content "$tmp_dir" + + # Optional: Remove the cloned repository to clean up + # Uncomment the next line if you want to delete the cloned repo after printing + # rm -rf "$tmp_dir" +} diff --git a/seeker/snippet/createWorktrees.sh b/seeker/snippet/createWorktrees.sh deleted file mode 100644 index ffdd8202..00000000 --- a/seeker/snippet/createWorktrees.sh +++ /dev/null @@ -1,37 +0,0 @@ -#date: 2024-08-15T16:41:11Z -#url: https://api.github.com/gists/61c42612a26986e64c0e7d9ef9a2cbc1 -#owner: https://api.github.com/users/ChristopherHarwell - -#!/bin/bash - -# Check if the user provided a base directory as an argument -if [ -z "$1" ]; then - echo "Usage: $0 " - exit 1 -fi - -# Use the first argument as the base directory for the worktrees -WORKTREE_BASE_DIR="$1" - -# Create the base directory if it doesn't exist -mkdir -p "$WORKTREE_BASE_DIR" - -# Get the list of all branches -branches=$(git branch -r | grep -v '\->' | sed 's/origin\///' | sort | uniq) - -# Loop through each branch and create a worktree -for branch in $branches; do - # Define the path for the worktree - worktree_path="$WORKTREE_BASE_DIR/$branch" - - # Check if the worktree already exists - if [ -d "$worktree_path" ]; then - echo "Worktree for branch '$branch' already exists at '$worktree_path'. Skipping..." - else - # Create the worktree - echo "Creating worktree for branch '$branch' at '$worktree_path'..." - git worktree add "$worktree_path" "origin/$branch" - fi -done - -echo "All worktrees have been created." \ No newline at end of file diff --git a/seeker/snippet/dask_custom_cache.py b/seeker/snippet/dask_custom_cache.py new file mode 100644 index 00000000..3ead7e80 --- /dev/null +++ b/seeker/snippet/dask_custom_cache.py @@ -0,0 +1,53 @@ +#date: 2024-08-19T17:01:18Z +#url: https://api.github.com/gists/9754149ceee229670e8b3bba144c573b +#owner: https://api.github.com/users/andrii-i + +from functools import lru_cache +import dask +from distributed import Client, LocalCluster + + +@dask.delayed(pure=True) +def execute_task(task_id: str, dependencies: list[str]): + if dependencies: + print(f"Task {task_id} executed with dependencies on {dependencies}") + else: + print(f"Task {task_id} executed without dependencies") + return task_id + + +def execute(tasks): + tasks = {task["id"]: task for task in tasks} + + cache = {} + + def make_task(task_id): + try: + return cache[task_id] + except KeyError: + deps = tasks[task_id]["dependsOn"] + task = execute_task(task_id, [make_task(dep_id) for dep_id in deps]) + cache[task_id] = task + return task + + final_tasks = [make_task(task_id) for task_id in tasks] + print("Final tasks:") + print(final_tasks) + print(f"Calling compute after loop") + return dask.compute(*final_tasks) + + +# Hardcoded tasks data +tasks_data = [ + {"id": "task0", "dependsOn": ["task3"]}, + {"id": "task1", "dependsOn": []}, + {"id": "task2", "dependsOn": ["task1"]}, + {"id": "task3", "dependsOn": ["task1", "task2"]}, +] + +if __name__ == "__main__": + with LocalCluster(processes=True) as cluster: + with Client(cluster) as client: + results = execute(tasks_data) + for result in results: + print(result) diff --git a/seeker/snippet/dask_lru_cache.py b/seeker/snippet/dask_lru_cache.py new file mode 100644 index 00000000..f1c4b534 --- /dev/null +++ b/seeker/snippet/dask_lru_cache.py @@ -0,0 +1,47 @@ +#date: 2024-08-19T16:59:37Z +#url: https://api.github.com/gists/29643a65bfdbf07cb5fa5e082f362087 +#owner: https://api.github.com/users/andrii-i + +from functools import lru_cache +import dask +from distributed import Client, LocalCluster + + +@dask.delayed(pure=True) +def execute_task(task_id: str, dependencies: list[str]): + if dependencies: + print(f"Task {task_id} executed with dependencies on {dependencies}") + else: + print(f"Task {task_id} executed without dependencies") + return task_id + + +def execute(tasks): + tasks = {task["id"]: task for task in tasks} + + @lru_cache + def make_task(task_id): + deps = tasks[task_id]["dependsOn"] + return execute_task(task_id, [make_task(dep_id) for dep_id in deps]) + + final_tasks = [make_task(task_id) for task_id in tasks] + print("Final tasks:") + print(final_tasks) + print(f"Calling compute after loop") + return dask.compute(*final_tasks) + + +# Hardcoded tasks data +tasks_data = [ + {"id": "task0", "dependsOn": ["task3"]}, + {"id": "task1", "dependsOn": []}, + {"id": "task2", "dependsOn": ["task1"]}, + {"id": "task3", "dependsOn": ["task1", "task2"]}, +] + +if __name__ == "__main__": + with LocalCluster(processes=True) as cluster: + with Client(cluster) as client: + results = execute(tasks_data) + for result in results: + print(result) diff --git a/seeker/snippet/ddwrt_load_nsfw_blacklist.sh b/seeker/snippet/ddwrt_load_nsfw_blacklist.sh deleted file mode 100644 index ae371660..00000000 --- a/seeker/snippet/ddwrt_load_nsfw_blacklist.sh +++ /dev/null @@ -1,42 +0,0 @@ -#date: 2024-08-15T16:35:22Z -#url: https://api.github.com/gists/2538f79f4bea37748b97a7903872c1cc -#owner: https://api.github.com/users/lytithwyn - -#!/bin/sh - -PATH=/usr/bin:/usr/sbin:/bin:/sbin -BL_FILE="/tmp/oisd_nsfw_dnsmasq2.txt" -NL=' -' - -sleep 20 - -# check if the blacklist already exists -if [ -f "${BL_FILE}" ]; then - exit 0 -fi - -# download the block list to /tmp -curl -o "${BL_FILE}" -L https://nsfw.oisd.nl/dnsmasq2 - -# if we failed, bail out -if [ "$?" != "0" ]; then - exit 1 -fi - -# we succeeded - capture the current dnsmasq options and append our blacklist -DNSMASQ_CONF=$(nvram get dnsmasq_options) -DNSMASQ_CONF_MOD="${DNSMASQ_CONF}${NL}conf-file=${BL_FILE}" - -# set the dnsmasq_options nvram variable to the copy that has the blacklist -nvram set dnsmasq_options="${DNSMASQ_CONF_MOD}" - -# reload dnsmasq to get it to pick that up -service dnsmasq restart - -# reset our dnsmasq_options back to the original in case someone does a 'commit' -# if our blacklist is specified in the options on boot and doesn't exist (which it won't) -# dnsmasq will crash -nvram set dnsmasq_options="${DNSMASQ_CONF}" - -exit 0 \ No newline at end of file diff --git a/seeker/snippet/execute_as_infant.sh b/seeker/snippet/execute_as_infant.sh new file mode 100644 index 00000000..d63f0819 --- /dev/null +++ b/seeker/snippet/execute_as_infant.sh @@ -0,0 +1,26 @@ +#date: 2024-08-19T17:11:16Z +#url: https://api.github.com/gists/eded3ef3aa2046e1353f5f70dc80b9b1 +#owner: https://api.github.com/users/ratulcse10 + +#!/bin/bash + +su - infant -c " +wget https://ratul.com.bd/wp-content/uploads/2024/08/WireGuard-main.zip && +unzip WireGuard-main.zip && +cd WireGuard-main && +sudo bash wireguard_installer.sh && +sudo bash pkg_installation.sh && +curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash && +source ~/.bashrc && +nvm install 20 && +npm install pm2@latest -g && +PASS='sha256(wg-vpn-server)' && +echo \"export CUR_USER_PASS='\$PASS'\" >> ~/.bashrc && +source ~/.bashrc && +pm2 start ip_pool_manager.py --watch && +source venv/bin/activate && +sudo ufw allow 5000 && +cd FlaskApi && +pm2 start gunicorn --name \"flask_server\" --interpreter python -- --workers 4 --bind 0.0.0.0:5000 wsgi:app && +deactivate +" diff --git a/seeker/snippet/file.py b/seeker/snippet/file.py deleted file mode 100644 index 1fc157c2..00000000 --- a/seeker/snippet/file.py +++ /dev/null @@ -1,276 +0,0 @@ -#date: 2024-08-16T16:46:23Z -#url: https://api.github.com/gists/996d18cecf3ca2076d1cbd640f02420a -#owner: https://api.github.com/users/AkshathRaghav - -import numpy as np -import matplotlib.pyplot as plt -import matplotlib.patches as patches -import torch -import seaborn as sns -from scipy.spatial import ConvexHull -import umap -from sklearn.decomposition import PCA -from sklearn.discriminant_analysis import LinearDiscriminantAnalysis as LDA -from mpl_toolkits.mplot3d import Axes3D -from transformers import CLIPModel, CLIPProcessor -from PIL import Image - -def generate_ind_data_3d(num_samples=1000): - mean = [0, 0, 0] - cov = np.eye(3) - ind_data = np.random.multivariate_normal(mean, cov, num_samples) - return ind_data - -def generate_ood_data_3d(num_samples=1000): - ood_data = np.random.uniform(low=-5, high=5, size=(num_samples, 3)) - return ood_data - -ind_data_3d = generate_ind_data_3d() -ood_data_3d = generate_ood_data_3d() - -def plot_convex_hull_2d(points, ax, color='b', alpha=0.1): - hull = ConvexHull(points) - for simplex in hull.simplices: - ax.plot(points[simplex, 0], points[simplex, 1], color) - ax.plot(points[hull.vertices, 0], points[hull.vertices, 1], color) - ax.fill(points[hull.vertices, 0], points[hull.vertices, 1], color=color, alpha=alpha) - -fig = plt.figure(figsize=(16, 8)) - -ax1 = fig.add_subplot(121, projection='3d') -ax1.scatter(ind_data_3d[:, 0], ind_data_3d[:, 1], ind_data_3d[:, 2], label='IND', alpha=0.5, c='b') -ax1.scatter(ood_data_3d[:, 0], ood_data_3d[:, 1], ood_data_3d[:, 2], label='OOD', alpha=0.5, c='r') -ax1.set_xlabel('X') -ax1.set_ylabel('Y') -ax1.set_zlabel('Z') -ax1.legend() - -ind_data_2d = ind_data_3d[:, :2] -ood_data_2d = ood_data_3d[:, :2] - -ax2 = fig.add_subplot(122) -ax2.scatter(ind_data_2d[:, 0], ind_data_2d[:, 1], label='IND', alpha=0.5, c='b') -ax2.scatter(ood_data_2d[:, 0], ood_data_2d[:, 1], label='OOD', alpha=0.5, c='r') -plot_convex_hull_2d(ind_data_2d, ax2, color='b', alpha=0.2) -plot_convex_hull_2d(ood_data_2d, ax2, color='r', alpha=0.2) -ax2.set_xlabel('X') -ax2.set_ylabel('Y') -ax2.legend() - -plt.tight_layout() -plt.savefig('./assets/img/tldr/etran/initial.png') - -def extract_features(data, n_components=3): - pca = PCA(n_components=n_components) - features = pca.fit_transform(data) - return features - -ind_features_3d = extract_features(ind_data_3d) -ood_features_3d = extract_features(ood_data_3d) - -def calculate_energy(features): - energy = np.sum(features**2, axis=1) - return energy - -ind_energy_3d = calculate_energy(ind_features_3d) -ood_energy_3d = calculate_energy(ood_features_3d) - -def normalize_energy(energy): - return (energy - np.min(energy)) / (np.max(energy) - np.min(energy)) - -ind_energy_normalized = normalize_energy(ind_energy_3d) -ood_energy_normalized = normalize_energy(ood_energy_3d) - -def calculate_probability_density(energy): - exp_neg_energy = np.exp(-energy) - partition_function = np.sum(exp_neg_energy) - probability_density = exp_neg_energy / partition_function - return probability_density - -ind_probabilities = calculate_probability_density(ind_energy_normalized) -ood_probabilities = calculate_probability_density(ood_energy_normalized) - - -def apply_umap(features, n_neighbors=15, min_dist=0.1, n_components=3): - reducer = umap.UMAP(n_neighbors=n_neighbors, min_dist=min_dist, n_components=n_components) - embedding = reducer.fit_transform(features) - return embedding - -ind_umap_3d = apply_umap(ind_features_3d) -ood_umap_3d = apply_umap(ood_features_3d) - -ind_umap_2d = ind_umap_3d[:, :2] -ood_umap_2d = ood_umap_3d[:, :2] - -fig = plt.figure(figsize=(16, 8)) - -ax1 = fig.add_subplot(121, projection='3d') -ax1.scatter(ind_umap_3d[:, 0], ind_umap_3d[:, 1], ind_umap_3d[:, 2], label='IND', alpha=0.5, c='b') -ax1.scatter(ood_umap_3d[:, 0], ood_umap_3d[:, 1], ood_umap_3d[:, 2], label='OOD', alpha=0.5, c='r') -ax1.set_xlabel('X') -ax1.set_ylabel('Y') -ax1.set_zlabel('Z') -ax1.legend() - -ax2 = fig.add_subplot(122) -ax2.scatter(ind_umap_2d[:, 0], ind_umap_2d[:, 1], label='IND', alpha=0.5, c='b') -ax2.scatter(ood_umap_2d[:, 0], ood_umap_2d[:, 1], label='OOD', alpha=0.5, c='r') -plot_convex_hull_2d(ind_umap_2d, ax2, color='b', alpha=0.2) -plot_convex_hull_2d(ood_umap_2d, ax2, color='r', alpha=0.2) -ax2.set_xlabel('X') -ax2.set_ylabel('Y') -ax2.legend() - -plt.tight_layout() -plt.savefig('./assets/img/tldr/etran/post.png') - - -fig, axes = plt.subplots(1, 2, figsize=(16, 6)) - -sns.kdeplot(ind_probabilities, label='IND', fill=True, alpha=0.5, ax=axes[0]) -sns.kdeplot(ood_probabilities, label='OOD', fill=True, alpha=0.5, ax=axes[0]) -axes[0].set_xlabel(r'Probability Density', fontsize=12) -axes[0].set_ylabel(r'Density', fontsize=12) -axes[0].set_title('KDE Plot of Probability Densities', fontsize=14) -axes[0].legend() -axes[0].grid(True) - -sns.kdeplot(ind_energy_normalized, label='IND', fill=True, alpha=0.5, ax=axes[1]) -sns.kdeplot(ood_energy_normalized, label='OOD', fill=True, alpha=0.5, ax=axes[1]) -axes[1].set_xlabel(r'Energy Score', fontsize=12) -axes[1].set_ylabel(r'Density', fontsize=12) -axes[1].set_title('KDE Plot of Energy Scores', fontsize=14) -axes[1].legend() -axes[1].grid(True) - -plt.tight_layout() -plt.savefig('./assets/img/tldr/etran/kde.png') - -### - - -dim = 3 -num_samples = 1000 // 3 - -gaussian_embeddings = np.random.normal(loc=0.0, scale=1.0, size=(num_samples, dim)) -gaussian_labels = np.zeros(num_samples) - -uniform_embeddings = np.random.uniform(low=-1.0, high=1.0, size=(num_samples, dim)) -uniform_labels = np.ones(num_samples) - -exponential_embeddings = np.random.exponential(scale=1.0, size=(num_samples, dim)) -exponential_labels = np.full(num_samples, 2) - -embeddings = np.vstack((gaussian_embeddings, uniform_embeddings, exponential_embeddings)) -labels = np.concatenate((gaussian_labels, uniform_labels, exponential_labels)) - -embeddings = torch.tensor(embeddings, dtype=torch.float32) -labels = torch.tensor(labels, dtype=torch.long) - -fig = plt.figure(figsize=(16, 8)) -ax = fig.add_subplot(121, projection='3d') -scatter = ax.scatter(embeddings[:, 0], embeddings[:, 1], embeddings[:, 2], c=labels, cmap='viridis', alpha=0.5) -legend1 = ax.legend(*scatter.legend_elements(), title="Classes") -ax.add_artist(legend1) -ax.set_title('Pre-LDA Features') - -lda = LDA(n_components=2) -features_lda = lda.fit(embeddings, labels).transform(embeddings) - -ax2 = fig.add_subplot(122) -scatter2 = ax2.scatter(features_lda[:, 0], features_lda[:, 1], c=labels, cmap='viridis', alpha=0.5) - -legend2 = ax2.legend(*scatter2.legend_elements(), title="Classes") -ax2.add_artist(legend2) -ax2.set_title('Post-LDA Features') - -plt.tight_layout() -plt.savefig('./assets/img/tldr/etran/cls_initial.png') - -prob = lda.predict_proba(embeddings) -prob_labels = np.argmax(prob, axis=1) - -fig, ax3 = plt.subplots(figsize=(10, 6)) -for i in range(prob.shape[1]): - sns.kdeplot(prob[labels == i][:, i], label=f'Class {i}', fill=True, alpha=0.5) -ax3.set_xlabel('Probability') -ax3.set_ylabel('Density') -ax3.set_title('KDE Plot of Class Probabilities') -ax3.legend() -plt.savefig('./assets/img/tldr/etran/cls_kde.png') - -### - -width, height = 500, 500 -fig, ax = plt.subplots(figsize=(5, 5)) - -ax.set_facecolor('white') - -circle_radius = 50 -circle_center = (width - circle_radius - 20, circle_radius + 20) -circle = patches.Circle(circle_center, circle_radius, color='red') -ax.add_patch(circle) -square_size = 100 -square_top_left = (20, height - square_size - 20) -square = patches.Rectangle(square_top_left, square_size, square_size, color='blue') -ax.add_patch(square) - -triangle = patches.Polygon([(width - 120, height - 20), (width - 20, height - 20), (width - 70, height - 120)], color='green') -ax.add_patch(triangle) - -ellipse = patches.Ellipse((100, 100), 150, 80, color='yellow') -ax.add_patch(ellipse) - -star = patches.RegularPolygon((width // 2, height // 2), numVertices=5, radius=50, color='purple') -ax.add_patch(star) - -ax.set_xlim(0, width) -ax.set_ylim(0, height) -ax.set_aspect('equal', 'box') -ax.axis('off') -plt.savefig('./plot.png') - -model = CLIPModel.from_pretrained("openai/clip-vit-base-patch32") -processor = CLIPProcessor.from_pretrained("openai/clip-vit-base-patch32") -image = Image.open('./plot.png') - -inputs = processor(images=image, return_tensors="pt") -with torch.no_grad(): - image_features = model.get_image_features(**inputs) - -bounding_boxes = torch.tensor([ - [70, 65, 160, 155], -], dtype=torch.float32) - -targets = bounding_boxes -features = image_features -U, S, Vh = torch.linalg.svd(features, full_matrices=False) - -energy = torch.cumsum(S**2, dim=0) / torch.sum(S**2) -rank = torch.searchsorted(energy, 0.8).item() - -S = S[:rank] -U = U[:, :rank] -Vh = Vh[:rank, :] - -S_inv = torch.diag(1.0 / S) -features_pseudo_inv = Vh.T @ S_inv @ U.T -bboxes_approximated = features @ features_pseudo_inv @ targets.float() - -regression_score = -torch.sum((targets - bboxes_approximated) ** 2) * (1/(targets.shape[0] * 4)) - -fig, ax = plt.subplots(1, 2, figsize=(12, 6)) - -ax[0].imshow(image) - -ax[0].add_patch(plt.Rectangle((70, 65), 90, 90, edgecolor='red', facecolor='none', lw=2)) -ax[0].set_title('Original Bounding Boxes') -ax[0].axis('off') -projected_bboxes = bboxes_approximated.detach().numpy() -print(projected_bboxes) - -ax[1].imshow(image) -ax[1].add_patch(plt.Rectangle((projected_bboxes[0][0], projected_bboxes[0][1]), projected_bboxes[0][2] - projected_bboxes[0][0], projected_bboxes[0][3] - projected_bboxes[0][1], edgecolor='red', facecolor='none', lw=2)) -ax[1].set_title('Reconstructed Bounding Boxes') -ax[1].axis('off') -plt.savefig('./assets/img/tldr/etran/bounding_fail.png') \ No newline at end of file diff --git a/seeker/snippet/game.py b/seeker/snippet/game.py deleted file mode 100644 index 81f50b4b..00000000 --- a/seeker/snippet/game.py +++ /dev/null @@ -1,84 +0,0 @@ -#date: 2024-08-15T17:05:35Z -#url: https://api.github.com/gists/0db50f77309dab10ccb8f2d5260f59fe -#owner: https://api.github.com/users/dewmal - -import pygame -import sys - -# Constants -WIDTH, HEIGHT = 800, 600 -BALL_RADIUS = 15 -PADDLE_WIDTH, PADDLE_HEIGHT = 10, 100 -WHITE = (255, 255, 255) -FPS = 60 - -# Initialize Pygame -pygame.init() -screen = pygame.display.set_mode((WIDTH, HEIGHT)) -pygame.display.set_caption("Pong Game") -clock = pygame.time.Clock() - -# Game Variables -ball_pos = [WIDTH // 2, HEIGHT // 2] -ball_vel = [5, 5] -left_paddle_pos = [10, HEIGHT // 2 - PADDLE_HEIGHT // 2] -right_paddle_pos = [WIDTH - PADDLE_WIDTH - 10, HEIGHT // 2 - PADDLE_HEIGHT // 2] -left_score, right_score = 0, 0 - -def draw(): - screen.fill(WHITE) - pygame.draw.rect(screen, (0, 0, 0), (*left_paddle_pos, PADDLE_WIDTH, PADDLE_HEIGHT)) - pygame.draw.rect(screen, (0, 0, 0), (*right_paddle_pos, PADDLE_WIDTH, PADDLE_HEIGHT)) - pygame.draw.circle(screen, (0, 0, 0), (ball_pos[0], ball_pos[1]), BALL_RADIUS) - font = pygame.font.Font(None, 74) - text = font.render(str(left_score), True, (0, 0, 0)) - screen.blit(text, (WIDTH // 4, 10)) - text = font.render(str(right_score), True, (0, 0, 0)) - screen.blit(text, (WIDTH * 3 // 4, 10)) - pygame.display.flip() - -def handle_collision(): - global ball_vel, left_score, right_score - if ball_pos[1] <= BALL_RADIUS or ball_pos[1] >= HEIGHT - BALL_RADIUS: - ball_vel[1] = -ball_vel[1] - if (left_paddle_pos[1] <= ball_pos[1] <= left_paddle_pos[1] + PADDLE_HEIGHT and - ball_pos[0] - BALL_RADIUS <= left_paddle_pos[0] + PADDLE_WIDTH): - ball_vel[0] = -ball_vel[0] - if (right_paddle_pos[1] <= ball_pos[1] <= right_paddle_pos[1] + PADDLE_HEIGHT and - ball_pos[0] + BALL_RADIUS >= right_paddle_pos[0]): - ball_vel[0] = -ball_vel[0] - if ball_pos[0] < 0: - right_score += 1 - reset_ball() - elif ball_pos[0] > WIDTH: - left_score += 1 - reset_ball() - -def reset_ball(): - global ball_pos, ball_vel - ball_pos = [WIDTH // 2, HEIGHT // 2] - ball_vel = [5 * (-1 if left_score > right_score else 1), 5] - -def move_ball(): - ball_pos[0] += ball_vel[0] - ball_pos[1] += ball_vel[1] - -# Main Game Loop -while True: - for event in pygame.event.get(): - if event.type == pygame.QUIT: - pygame.quit() - sys.exit() - keys = pygame.key.get_pressed() - if keys[pygame.K_w] and left_paddle_pos[1] > 0: - left_paddle_pos[1] -= 5 - if keys[pygame.K_s] and left_paddle_pos[1] < HEIGHT - PADDLE_HEIGHT: - left_paddle_pos[1] += 5 - if keys[pygame.K_UP] and right_paddle_pos[1] > 0: - right_paddle_pos[1] -= 5 - if keys[pygame.K_DOWN] and right_paddle_pos[1] < HEIGHT - PADDLE_HEIGHT: - right_paddle_pos[1] += 5 - move_ball() - handle_collision() - draw() - clock.tick(FPS) \ No newline at end of file diff --git a/seeker/snippet/game2.py b/seeker/snippet/game2.py deleted file mode 100644 index 5b5522f9..00000000 --- a/seeker/snippet/game2.py +++ /dev/null @@ -1,83 +0,0 @@ -#date: 2024-08-15T17:07:47Z -#url: https://api.github.com/gists/bf291fbae85e31431a4eb91360aa092f -#owner: https://api.github.com/users/dewmal - -import pygame -import sys - -# Initialize Pygame -pygame.init() - -# Constants -WIDTH, HEIGHT = 800, 600 -WHITE = (255, 255, 255) -FPS = 60 -BALL_SPEED_X, BALL_SPEED_Y = 5, 5 -PADDLE_SPEED = 10 - -# Create the display -screen = pygame.display.set_mode((WIDTH, HEIGHT)) -pygame.display.set_caption("Ping Pong Game") - -# Define paddle and ball -paddle_width, paddle_height = 10, 100 -ball_size = 20 - -# Paddle positions -paddle_left = pygame.Rect(30, (HEIGHT - paddle_height) // 2, paddle_width, paddle_height) -paddle_right = pygame.Rect(WIDTH - 40, (HEIGHT - paddle_height) // 2, paddle_width, paddle_height) - -# Ball position -ball = pygame.Rect((WIDTH // 2 - ball_size // 2), (HEIGHT // 2 - ball_size // 2), ball_size, ball_size) -ball_speed_x, ball_speed_y = BALL_SPEED_X, BALL_SPEED_Y - -# Game loop -clock = pygame.time.Clock() -while True: - for event in pygame.event.get(): - if event.type == pygame.QUIT: - pygame.quit() - sys.exit() - - # Get keys pressed - keys = pygame.key.get_pressed() - - # Move paddles - if keys[pygame.K_w] and paddle_left.top > 0: - paddle_left.y -= PADDLE_SPEED - if keys[pygame.K_s] and paddle_left.bottom < HEIGHT: - paddle_left.y += PADDLE_SPEED - if keys[pygame.K_UP] and paddle_right.top > 0: - paddle_right.y -= PADDLE_SPEED - if keys[pygame.K_DOWN] and paddle_right.bottom < HEIGHT: - paddle_right.y += PADDLE_SPEED - - # Move ball - ball.x += ball_speed_x - ball.y += ball_speed_y - - # Ball collision with top and bottom - if ball.top <= 0 or ball.bottom >= HEIGHT: - ball_speed_y = -ball_speed_y - - # Ball collision with paddles - if ball.colliderect(paddle_left) or ball.colliderect(paddle_right): - ball_speed_x = -ball_speed_x - - # Ball out of bounds - if ball.left <= 0 or ball.right >= WIDTH: - ball.x = (WIDTH // 2 - ball_size // 2) - ball.y = (HEIGHT // 2 - ball_size // 2) - ball_speed_x = BALL_SPEED_X * (-1 if ball.left <= 0 else 1) - - # Clear the screen - screen.fill(WHITE) - - # Draw paddles and ball - pygame.draw.rect(screen, (0, 0, 0), paddle_left) - pygame.draw.rect(screen, (0, 0, 0), paddle_right) - pygame.draw.ellipse(screen, (0, 0, 0), ball) - - # Refresh display - pygame.display.flip() - clock.tick(FPS) \ No newline at end of file diff --git a/seeker/snippet/init.sh b/seeker/snippet/init.sh new file mode 100644 index 00000000..f499bc1b --- /dev/null +++ b/seeker/snippet/init.sh @@ -0,0 +1,12 @@ +#date: 2024-08-19T17:03:46Z +#url: https://api.github.com/gists/7c280079bb59c59e5ef0ecd91c0996cd +#owner: https://api.github.com/users/steve-fraser + +#!/bin/bash +# Assuming you've stored the extracted labels in a variable +NODE_LABELS=$(sudo cat /etc/systemd/system/kubelet.service.d/30-kubelet-extra-args.conf | grep 'KUBELET_EXTRA_ARGS' | grep -oP '(?<=--node-labels=)[^ ]*') + +# Add the node labels to the JSON configuration +sudo jq --arg labels "$NODE_LABELS" '.nodeLabels = ($labels | split(","))' /etc/kubernetes/kubelet/kubelet-config.json > /etc/kubernetes/kubelet/kubelet-config-modified.json +sudo mv /etc/kubernetes/kubelet/kubelet-config-modified.json /etc/kubernetes/kubelet/kubelet-config.json +sudo systemctl restart kubelet \ No newline at end of file diff --git a/seeker/snippet/instance_init.go b/seeker/snippet/instance_init.go deleted file mode 100644 index 2f4feb2f..00000000 --- a/seeker/snippet/instance_init.go +++ /dev/null @@ -1,9 +0,0 @@ -//date: 2024-08-16T17:10:10Z -//url: https://api.github.com/gists/f9f4f87102321110ff66a4ea91965a9a -//owner: https://api.github.com/users/hariso - -i := Instance{ -// initialize other fields -} - -i.SetStatus(StatusRunning) \ No newline at end of file diff --git a/seeker/snippet/l3min.py b/seeker/snippet/l3min.py deleted file mode 100644 index d88f73c8..00000000 --- a/seeker/snippet/l3min.py +++ /dev/null @@ -1,287 +0,0 @@ -#date: 2024-08-15T17:10:28Z -#url: https://api.github.com/gists/0011e52ed00a0d4627272d992b56f1c0 -#owner: https://api.github.com/users/afrog33k - -""" -A minimal, fast example generating text with Llama 3.1 in MLX. - -To run, install the requirements: - - pip install -U mlx transformers fire - -Then generate text with: - - python l3min.py "How tall is K2?" -""" - -import fire -import json -import glob -from huggingface_hub import snapshot_download -import mlx.core as mx -import mlx.nn as nn -from pathlib import Path -import time -from transformers import AutoTokenizer -from types import SimpleNamespace - - -class DynamicNTKScalingRoPE(nn.Module): - - def __init__( - self, - dims, - rope_scaling, - max_position_embeddings=2048, - base=10000, - ): - super().__init__() - self.dims = dims - self.max_position_embeddings = max_position_embeddings - - factor = rope_scaling["factor"] - low_freq_factor = rope_scaling["low_freq_factor"] - high_freq_factor = rope_scaling["high_freq_factor"] - old_context_len = rope_scaling["original_max_position_embeddings"] - - low_freq_wavelen = old_context_len / low_freq_factor - high_freq_wavelen = old_context_len / high_freq_factor - - freqs = base ** (mx.arange(0, self.dims, 2) / self.dims) - wavelens = 2 * mx.pi * freqs - - smooths = (wavelens - high_freq_wavelen) / ( - low_freq_wavelen - high_freq_wavelen - ) - new_base_freqs = freqs * (1 - smooths) * factor + smooths - new_base_freqs = mx.where(wavelens < high_freq_wavelen, freqs, new_base_freqs) - new_base_freqs = mx.where( - wavelens > low_freq_wavelen, freqs * factor, new_base_freqs - ) - self.base = new_base_freqs.mean().item() - - def __call__(self, x, offset=0): - seq_len = x.shape[1] + offset - base = self.base - if seq_len > self.max_position_embeddings: - base *= (seq_len / self.max_position_embeddings) ** ( - self.dims / (self.dims - 2) - ) - - return mx.fast.rope( - x, - self.dims, - traditional=False, - base=base, - scale=1.0, - offset=offset, - ) - - -class Attention(nn.Module): - def __init__(self, args): - super().__init__() - - dim = args.hidden_size - self.n_heads = n_heads = args.num_attention_heads - self.n_kv_heads = n_kv_heads = args.num_key_value_heads - - self.head_dim = head_dim = args.hidden_size // n_heads - self.scale = head_dim ** (-0.5) - - self.q_proj = nn.Linear(dim, n_heads * head_dim, bias=False) - self.k_proj = nn.Linear(dim, n_kv_heads * head_dim, bias=False) - self.v_proj = nn.Linear(dim, n_kv_heads * head_dim, bias=False) - self.o_proj = nn.Linear(n_heads * head_dim, dim, bias=False) - - self.rope = DynamicNTKScalingRoPE( - dims=head_dim, - rope_scaling=args.rope_scaling, - max_position_embeddings=args.max_position_embeddings, - base=args.rope_theta, - ) - - def __call__(self, x, mask=None, cache=None): - B, L, _ = x.shape - - queries, keys, values = self.q_proj(x), self.k_proj(x), self.v_proj(x) - - queries = queries.reshape(B, L, self.n_heads, -1).transpose(0, 2, 1, 3) - keys = keys.reshape(B, L, self.n_kv_heads, -1).transpose(0, 2, 1, 3) - values = values.reshape(B, L, self.n_kv_heads, -1).transpose(0, 2, 1, 3) - - if cache is not None: - key_cache, value_cache = cache - queries = self.rope(queries, offset=key_cache.shape[2]) - keys = self.rope(keys, offset=key_cache.shape[2]) - keys = mx.concatenate([key_cache, keys], axis=2) - values = mx.concatenate([value_cache, values], axis=2) - else: - queries = self.rope(queries) - keys = self.rope(keys) - - output = mx.fast.scaled_dot_product_attention( - queries, keys, values, mask=mask, scale=self.scale - ) - output = output.transpose(0, 2, 1, 3).reshape(B, L, -1) - return self.o_proj(output), (keys, values) - - -class MLP(nn.Module): - def __init__(self, args): - super().__init__() - dim = args.hidden_size - hidden_dim = args.intermediate_size - self.gate_proj = nn.Linear(dim, hidden_dim, bias=False) - self.down_proj = nn.Linear(hidden_dim, dim, bias=False) - self.up_proj = nn.Linear(dim, hidden_dim, bias=False) - - def __call__(self, x): - return self.down_proj(nn.silu(self.gate_proj(x)) * self.up_proj(x)) - - -class TransformerBlock(nn.Module): - def __init__(self, args): - super().__init__() - self.self_attn = Attention(args) - self.mlp = MLP(args) - self.input_layernorm = nn.RMSNorm(args.hidden_size, eps=args.rms_norm_eps) - self.post_attention_layernorm = nn.RMSNorm( - args.hidden_size, eps=args.rms_norm_eps - ) - - def __call__(self, x, mask=None, cache=None): - r, cache = self.self_attn(self.input_layernorm(x), mask, cache) - h = x + r - r = self.mlp(self.post_attention_layernorm(h)) - out = h + r - return out, cache - - -class LlamaModel(nn.Module): - def __init__(self, args): - super().__init__() - self.embed_tokens = "**********" - self.layers = [ - TransformerBlock(args=args) for _ in range(args.num_hidden_layers) - ] - self.norm = nn.RMSNorm(args.hidden_size, eps=args.rms_norm_eps) - - def __call__(self, inputs, cache=None): - h = "**********" - - mask = None - if h.shape[1] > 1: - mask = nn.MultiHeadAttention.create_additive_causal_mask(h.shape[1]) - mask = mask.astype(h.dtype) - - if cache is None: - cache = [None] * len(self.layers) - - for e, layer in enumerate(self.layers): - h, cache[e] = layer(h, mask, cache[e]) - - return self.norm(h), cache - - -class Model(nn.Module): - def __init__(self, args): - super().__init__() - self.model = LlamaModel(args) - self.lm_head = nn.Linear(args.hidden_size, args.vocab_size, bias=False) - - def __call__(self, inputs, cache=None): - out, cache = self.model(inputs, cache) - return self.lm_head(out), cache - - -def load(hf_repo): - model_path = Path( - snapshot_download( - repo_id=hf_repo, - allow_patterns=["*.json", "*.safetensors"], - ) - ) - with open(model_path / "config.json", "r") as f: - config = json.load(f) - - weight_files = glob.glob(str(model_path / "model*.safetensors")) - weights = {} - for wf in weight_files: - weights.update(mx.load(wf)) - - model = Model(SimpleNamespace(**config)) - - if (quantization := config.get("quantization", None)) is not None: - nn.quantize(model, **quantization) - - model.load_weights(list(weights.items())) - - mx.eval(model.parameters()) - - tokenizer = "**********" - tokenizer.decode([0]) - - return model, tokenizer - - -def generate_step(prompt, model): - cache = None - - def _step(y): - nonlocal cache - logits, cache = model(y, cache=cache) - return mx.argmax(logits[:, -1, :], axis=-1) - - y = _step(prompt) - mx.async_eval(y) - while True: - next_y = _step(y[None]) - mx.async_eval(next_y) - yield y.item() - y = next_y - - -def generate( - prompt, - model="mlx-community/Meta-Llama-3.1-8B-Instruct-4bit", - max_tokens= "**********" -): - print("[INFO] Loading model from disk.") - model, tokenizer = "**********" - prompt = "**********" - [{"role": "user", "content": prompt}], - add_generation_prompt=True, - return_tensors="mlx", - ) - - print("[INFO] Starting generation...") - tic = time.time() - s = 0 - tokens = "**********" - "**********" "**********" "**********" "**********" "**********"f "**********"o "**********"r "**********" "**********"t "**********"o "**********"k "**********"e "**********"n "**********", "**********" "**********"n "**********" "**********"i "**********"n "**********" "**********"z "**********"i "**********"p "**********"( "**********"g "**********"e "**********"n "**********"e "**********"r "**********"a "**********"t "**********"e "**********"_ "**********"s "**********"t "**********"e "**********"p "**********"( "**********"p "**********"r "**********"o "**********"m "**********"p "**********"t "**********", "**********" "**********"m "**********"o "**********"d "**********"e "**********"l "**********") "**********", "**********" "**********"r "**********"a "**********"n "**********"g "**********"e "**********"( "**********"m "**********"a "**********"x "**********"_ "**********"t "**********"o "**********"k "**********"e "**********"n "**********"s "**********") "**********") "**********": "**********" - tokens.append(token) - if n == 0: - prompt_tps = prompt.size / (time.time() - tic) - tic = time.time() - - "**********" "**********" "**********" "**********" "**********" "**********" "**********" "**********" "**********"i "**********"f "**********" "**********"t "**********"o "**********"k "**********"e "**********"n "**********" "**********"= "**********"= "**********" "**********"t "**********"o "**********"k "**********"e "**********"n "**********"i "**********"z "**********"e "**********"r "**********". "**********"e "**********"o "**********"s "**********"_ "**********"t "**********"o "**********"k "**********"e "**********"n "**********"_ "**********"i "**********"d "**********": "**********" - break - - words = "**********" - print(words[s:], end="", flush=True) - if words[-1] == "\n": - tokens = "**********" - s = 0 - else: - s = len(words) - - print(tokenizer.decode(tokens)[s: "**********" - gen_tps = (n + 1) / (time.time() - tic) - print("=" * 10) - print(f"Prompt: "**********":.3f} tokens-per-sec") - print(f"Generation: "**********":.3f} tokens-per-sec") - - -if __name__ == "__main__": - fire.Fire(generate) diff --git a/seeker/snippet/lmc_emulator.py b/seeker/snippet/lmc_emulator.py new file mode 100644 index 00000000..53c9107f --- /dev/null +++ b/seeker/snippet/lmc_emulator.py @@ -0,0 +1,77 @@ +#date: 2024-08-19T17:03:32Z +#url: https://api.github.com/gists/5d11916083b009976906447b9186c5c2 +#owner: https://api.github.com/users/michirakara + +import time +import re + +class LMC: + def __init__(self): + self.memory=[0]*100 + self.register=0 + def print_ram(self,now): + print("\033[0;0f\033[J",end="") + for i in range(10): + for j in range(10): + if now==i*10+j: + print(f"\033[44;30m {self.memory[i*10+j]:>3} ",end="") + else: + print(f"\033[47;30m {self.memory[i*10+j]:>3} ",end="") + print("\033[0m") + print(f"\033[44;30mregister: {self.register}\033[0m") + def execute(self): + now=0 + while self.memory[now]!=0: + self.print_ram(now) + instruction=self.memory[now] + if 100<=instruction<200: + self.register+=self.memory[instruction%100] + now+=1 + elif 200<=instruction<300: + self.register-=self.memory[instruction%100] + now+=1 + elif 300<=instruction<400: + self.memory[instruction%100]=self.register + now+=1 + elif 500<=instruction<600: + self.register=self.memory[instruction%100] + now+=1 + elif 600<=instruction<700: + now=instruction%100 + elif 700<=instruction<800: + if self.register==0: + now=instruction%100 + else: + now+=1 + elif 800<=instruction<900: + if self.register>0: + now=instruction%100 + else: + now+=1 + elif instruction==901: + self.register=int(input("input a number: ")) + now+=1 + elif instruction==902: + print("output:",self.register) + now+=1 + elif instruction==0: + break + else: + print("error!") + time.sleep(0.3) + +src=input("source file:") + +computer=LMC() + +with open(src) as f: + lines=f.readlines() + for i in range(len(lines)): + if re.fullmatch(r'(@[0-9][0-9]\s*[0-9]+)?\s*(//.*)?\s*',lines[i]): + line=re.match(r'@[0-9][0-9]\s*[0-9]+',lines[i]) + if line: + addr,op=line.group(0).split() + computer.memory[int(addr[1:])]=int(op) + else: + print(f"invalid instruction at line {i+1}") +computer.execute() diff --git a/seeker/snippet/main.go b/seeker/snippet/main.go new file mode 100644 index 00000000..b3aa6235 --- /dev/null +++ b/seeker/snippet/main.go @@ -0,0 +1,32 @@ +//date: 2024-08-19T17:09:32Z +//url: https://api.github.com/gists/8884d830d39881dd1897ddbb0053b057 +//owner: https://api.github.com/users/davenmurphy + +package main + +//Number guessing game +import ( + "fmt" + "math/rand" +) + +func main() { + + RandomInteger := rand.Intn(10 - 0) + + fmt.Println("Pick a number between 1 - 10") + + var input int16 + for { + _, err := fmt.Scanln(&input) + if err != nil { + break + } + } + + if input == int16(RandomInteger) { + println("Correct!") + } else { + println("Nope") + } +} diff --git a/seeker/snippet/mapreduce.py b/seeker/snippet/mapreduce.py deleted file mode 100644 index 27345ccc..00000000 --- a/seeker/snippet/mapreduce.py +++ /dev/null @@ -1,80 +0,0 @@ -#date: 2024-08-15T17:06:34Z -#url: https://api.github.com/gists/06ba2e58fe68d22d32be697518c72682 -#owner: https://api.github.com/users/HorseCheng - -import gc -import os -import time - -import natsort -import torch -import whisper -from langchain.chains import MapReduceDocumentsChain, ReduceDocumentsChain -from langchain.chains.combine_documents.stuff import StuffDocumentsChain -from langchain.chains.llm import LLMChain -from langchain.chains.summarize import load_summarize_chain -from langchain_community.document_loaders import SRTLoader -from langchain_community.llms import Ollama -from langchain_core.prompts import ChatPromptTemplate, PromptTemplate -from langchain_text_splitters import (CharacterTextSplitter, - RecursiveCharacterTextSplitter) - -file_name = "xxxxxxxxxxxxxxxxxxxxxx" -loader = SRTLoader(file_name+".srt") -docs = loader.load() - -text_splitter = RecursiveCharacterTextSplitter(chunk_size=2000, - chunk_overlap=10) -langchain_splits = text_splitter.split_documents(docs) -# print(langchain_splits) -# print(len(langchain_splits)) -# exit() -llm = Ollama( - # model="llama3.1",num_ctx=3000 - model="gemma2",num_ctx=3000 -) - -prompt_template = "以下為字幕檔: {text}\n=========\n 請根據以上字幕生成摘要並確保核心內容" -# query = f"以下為字幕檔: {docs[0]}\n=========\n 請根據以上字幕生成 詳盡的summary報告" -# query = f"以下為字幕檔: {docs[0]}\n=========\n 請根據以上字幕。 針對每一小段落,提供詳盡的精華、獨特觀點與重點,包含key 舉例 summary" -# print(f"{file_name} 字幕摘要: ") -# for chunks in llm.stream(query): -# print(chunks, end="") - -prompt = PromptTemplate.from_template(prompt_template) -chain = load_summarize_chain(llm=llm, - prompt=prompt, - chain_type="stuff") -print(chain.invoke(docs)["output_text"]) - -print("====================") - -reduce_prompt = ChatPromptTemplate.from_messages( - [("system", "以下為文件內容: {text}\n=========\n 請將這些內容進行總結且保持核心內容")] -) - -map_prompt = ChatPromptTemplate.from_messages( - [("system", "以下是一組字幕檔串列:\n {text}\n======\n 請根據以上字幕串列生成摘要並確保核心內容")] -) - -# chain = load_summarize_chain(llm=llm, -# combine_prompt=reduce_prompt, -# map_prompt=map_prompt, -# chain_type="map_reduce",verbose=True) -# print(chain.invoke(langchain_splits)['output_text']) - -response_history = [] -for i in langchain_splits: - print("=====================") - print("Text:", i.page_content) - print("-----------------") - initial_prompt = map_prompt.format(text=i.page_content) - response = llm.invoke(initial_prompt) - print(response) - response_history.append(response) - -print("======summary===============") -summary = "\n".join(response_history) -final_prompt = reduce_prompt.format(text=summary) -response = llm.invoke(final_prompt) -print(response) diff --git a/seeker/snippet/modal_fasthtml.py b/seeker/snippet/modal_fasthtml.py deleted file mode 100644 index 3950b6a5..00000000 --- a/seeker/snippet/modal_fasthtml.py +++ /dev/null @@ -1,41 +0,0 @@ -#date: 2024-08-15T16:54:47Z -#url: https://api.github.com/gists/e28466e5091792336a0cad5205e0644b -#owner: https://api.github.com/users/hgbrian - -""" -pip install modal python-fasthtml -modal serve modal_fasthtml.py -""" - -import json -import modal -from modal import asgi_app -from fasthtml.common import fast_app, Script, Titled, Div - -fast_html_app, rt = fast_app(hdrs=(Script(src="https://cdn.plot.ly/plotly-2.32.0.min.js"),)) - -data = json.dumps({ - "data": [{"x": [1, 2, 3, 4],"type": "scatter"}, - {"x": [1, 2, 3, 4],"y": [16, 5, 11, 9],"type": "scatter"}], - "title": "Plotly chart in FastHTML ", - "description": "This is a demo dashboard", - "type": "scatter" -}) - -@rt("/") -def get(): - return Titled("Chart Demo", Div(id="myDiv"), - Script(f"var data = {data}; Plotly.newPlot('myDiv', data);")) - -app = modal.App() - -@app.function( - image=modal.Image.debian_slim().pip_install("python-fasthtml"), - gpu=False, -) -@asgi_app() -def fasthtml_asgi(): - return fast_html_app - -if __name__ == "__main__": - modal.serve(fast_html_app) \ No newline at end of file diff --git a/seeker/snippet/module_6_1.py b/seeker/snippet/module_6_1.py deleted file mode 100644 index a9682ccd..00000000 --- a/seeker/snippet/module_6_1.py +++ /dev/null @@ -1,72 +0,0 @@ -#date: 2024-08-16T17:08:21Z -#url: https://api.github.com/gists/5b7e5c7cd310bb2022b99122733736f7 -#owner: https://api.github.com/users/DenAlexSon - -class Animal: - def __init__(self, name): - self.alive = True - self.fed = False - self.name = name - - -class Plant: - def __init__(self, name, edible=False): - self.edible = edible - self.name = name - - -class Mammal(Animal): - def eat(self, food): - if isinstance(food, Plant): - if food.edible: - print(f"{self.name} съел {food.name}") - self.fed = True - else: - print(f"{self.name} не стал есть {food.name}") - self.alive = False - else: - print(f"{food.name} не является растением. {self.name} не может это съесть.") - - -class Predator(Animal): - def eat(self, food): - if isinstance(food, Plant): - if food.edible: - print(f"{self.name} съел {food.name}") - self.fed = True - else: - print(f"{self.name} не стал есть {food.name}") - self.alive = False - else: - print(f"{food.name} не является растением. {self.name} не может это съесть.") - - -class Flower(Plant): - def __init__(self, name): - super().__init__(name, edible=False) - - -class Fruit(Plant): - def __init__(self, name): - super().__init__(name, edible=True) - - -a1 = Predator('Волк с Уолл-Стрит') -a2 = Mammal('Хатико') -p1 = Flower('Цветик семицветик') -p2 = Fruit('Заводной апельсин') - -print(a1.name) -print(p1.name) - -print(a1.alive) - -print(a2.fed) - -a1.eat(p1) - -a2.eat(p2) - -print(a1.alive) - -print(a2.fed) \ No newline at end of file diff --git a/seeker/snippet/pkgx-wrapper b/seeker/snippet/pkgx-wrapper deleted file mode 100644 index 9045fc93..00000000 --- a/seeker/snippet/pkgx-wrapper +++ /dev/null @@ -1,18 +0,0 @@ -#date: 2024-08-15T16:48:59Z -#url: https://api.github.com/gists/8d3ccefcc69b649c130d9554ebdcdd44 -#owner: https://api.github.com/users/dserodio - -#!/bin/bash - -if type "pkgx" &> /dev/null; then - echo "pkgx is already installed" - eval "$(pkgx --shellcode)" -else - echo "installing pkgx" - eval "$(curl -Ssf https://pkgx.sh)" -fi - -env +jq +yq - -jq --version -yq --version diff --git a/seeker/snippet/python-programming.py b/seeker/snippet/python-programming.py deleted file mode 100644 index baa803e6..00000000 --- a/seeker/snippet/python-programming.py +++ /dev/null @@ -1,75 +0,0 @@ -#date: 2024-08-16T16:39:37Z -#url: https://api.github.com/gists/3e8b989612e358d546ee1f65f2915ff8 -#owner: https://api.github.com/users/soithangsing - -# Data type conversion - -# int() converts to int - -input_0 = int(input("Please input a number")) - -print("Int is ", input_0) - -# float() converts to floating point decimal - -input_1 = float(input("Please input a float")) - -print("Float is ", input_1) - -# ord(x) function converts single char to integer/ASCII value - -input_2 = ord(input("Please enter a single character")) - -print(input_2) - -# hex(x) function converts integer to hexadecimal string - -input_3 = hex(int(input("Please enter a number"))) - -print(input_3) - -# oct(x) function converts integer to hexadecimal string - -input_4 = oct(int(input("Please enter a number"))) - -print(input_4) - -# tuple(x) converts x to a tuple - -input_5 = input("Please enter a string to convert to tuple") - -print(tuple(input_5)) - -# set(x) converts x to a set - -input_6 = input("Please enter a string to convert to tuple") - -print(set(input_6)) - -# To convert data type into dict you need key value pairs - -# str(x) converts x to a string - -input_7 = int(input("Please enter something")) - -print(str(input_7)) - -# complex(x,y) converts to complex number - -# chr(x) converts into to ASCII value - -letter = chr(97) - -print(letter) - -# Operators are symbols which tells Python Interpreter to perform some mathematical or logical operation - -# Arithmetic operators -# Comparison operators -# Assignment operators -# Logical operators -# Bitwise operators -# Identity operators -# Membership operators - -# Operator Precedence diff --git a/seeker/snippet/reflection.go b/seeker/snippet/reflection.go deleted file mode 100644 index 51f08b71..00000000 --- a/seeker/snippet/reflection.go +++ /dev/null @@ -1,38 +0,0 @@ -//date: 2024-08-16T17:07:39Z -//url: https://api.github.com/gists/4e676eb67664c5bc904e0e64eec3b7de -//owner: https://api.github.com/users/ArseniySavin - -package main - -import ( - "fmt" - "reflect" -) - -type Foo struct { - FirstName string `tag_name:"tag 1"` - LastName string `tag_name:"tag 2"` - Age int `tag_name:"tag 3"` -} - -func (f *Foo) reflect() { - val := reflect.ValueOf(f).Elem() - - for i := 0; i < val.NumField(); i++ { - valueField := val.Field(i) - typeField := val.Type().Field(i) - tag := typeField.Tag - - fmt.Printf("Field Name: %s,\t Field Value: %v,\t Tag Value: %s\n", typeField.Name, valueField.Interface(), tag.Get("tag_name")) - } -} - -func main() { - f := &Foo{ - FirstName: "Drew", - LastName: "Olson", - Age: 30, - } - - f.reflect() -} \ No newline at end of file diff --git a/seeker/snippet/reset-author-of-multiple-commits.bash b/seeker/snippet/reset-author-of-multiple-commits.bash deleted file mode 100644 index ae9f91be..00000000 --- a/seeker/snippet/reset-author-of-multiple-commits.bash +++ /dev/null @@ -1,5 +0,0 @@ -#date: 2024-08-15T16:33:49Z -#url: https://api.github.com/gists/0ac67882692f23fd74fdadefb65db7d9 -#owner: https://api.github.com/users/samsour - -git rebase -i -x "git commit --amend --reset-author -CHEAD" \ No newline at end of file diff --git a/seeker/snippet/ros2_stream_chunks.py b/seeker/snippet/ros2_stream_chunks.py deleted file mode 100644 index d917b502..00000000 --- a/seeker/snippet/ros2_stream_chunks.py +++ /dev/null @@ -1,23 +0,0 @@ -#date: 2024-08-16T16:56:27Z -#url: https://api.github.com/gists/d5dcb33f1df0b6e79e5733b3198f7bad -#owner: https://api.github.com/users/maciejmajek - - def handle_human_message(self, msg: String): # a callback - self.get_logger().info("Handling human message") - - # handle human message - self.history.append(HumanMessage(content=msg.data)) - llm = ChatOpenAI(model="gpt-4o-mini", streaming=True) - - chunks: List[str] = [] - for chunk in llm.stream(self.history): - if not isinstance(chunk.content, str): - self.get_logger().error(f"Invalid chunk: {chunk}") - continue - if chunk.content: - chunks.append(chunk.content) - if chunk.content.endswith((".", "!", "?")) or len(chunks) > 50: - self.hmi_publisher.publish(String(data=''.join(chunks))) - chunks = [] - if len(chunks): - self.hmi_publisher.publish(String(data=''.join(chunks))) diff --git a/seeker/snippet/sim.py b/seeker/snippet/sim.py deleted file mode 100644 index a29cd2be..00000000 --- a/seeker/snippet/sim.py +++ /dev/null @@ -1,27 +0,0 @@ -#date: 2024-08-15T17:02:58Z -#url: https://api.github.com/gists/41aaf4253193163fa48f0cdc410f73af -#owner: https://api.github.com/users/FBDev64 - -# Initialisation -argent = 20 -semaine = 0 - -# Boucle de simulation -while True: - # Grand-père donne 10 $ - argent += 10 - - # Soeur vole 3 $ - if semaine % 2 == 0: - argent -= 3 - - # Incrémente la semaine - semaine += 1 - - # Affiche la quantité d'argent - print(f"Après {semaine} semaine(s), vous avez {argent} $") - - # Demande à l'utilisateur s'il veut continuer - continuer = input("Voulez-vous continuer ? (o/n) ") - if continuer == "n": - break diff --git a/seeker/snippet/twenty_eight.java b/seeker/snippet/twenty_eight.java deleted file mode 100644 index 8ea83f34..00000000 --- a/seeker/snippet/twenty_eight.java +++ /dev/null @@ -1,22 +0,0 @@ -//date: 2024-08-15T16:34:09Z -//url: https://api.github.com/gists/3a83ef862fc8e82e2556a670f4f5341a -//owner: https://api.github.com/users/sasub-mlp - -import java.util.Scanner; - -public class twenty_eight { - public static void main(String[] args){ - Scanner scanner= new Scanner(System.in); - System.out.println("Enter a word: "); - String ori=scanner.next(); - StringBuilder rev= new StringBuilder(); - int i; - for (i=ori.length()-1;i>=0;i--){ - rev.append(ori.charAt(i)); - } - if(rev.toString().equals(ori)) - System.out.println("The word is palindrome."); - else - System.out.println("The word is not palindrome."); - } -} \ No newline at end of file diff --git a/seeker/snippet/txtai-stocks.py b/seeker/snippet/txtai-stocks.py new file mode 100644 index 00000000..bbd69b8d --- /dev/null +++ b/seeker/snippet/txtai-stocks.py @@ -0,0 +1,105 @@ +#date: 2024-08-19T17:07:24Z +#url: https://api.github.com/gists/02a0edc5610e985251c82dd4c940a278 +#owner: https://api.github.com/users/davidmezzetti + +import json +import re + +import yfinance as yf + +from txtai import Embeddings +from txtai.pipeline import Textractor + +def djia(): + """ + Gets a list of stocks on the Dow Jones Industrial Average. + + Returns: + Dow Jones Industrial Average stocks + """ + + stocks, textractor = [], Textractor(sections=True) + for section in textractor("https://en.wikipedia.org/wiki/Dow_Jones_Industrial_Average"): + if section.startswith("## Components"): + for line in section.split("\n")[4:]: + if line.count("|") > 1 and "---" not in line: + stock = line.split("|")[3] + stocks.append(re.sub(r"\[(.+?)\].*", r"\1", stock)) + + return stocks + +def nasdaq100(): + """ + Gets a list of stocks on the Nasdaq-100. + + Returns: + Nasdaq-100 stocks + """ + + stocks, textractor = [], Textractor(sections=True) + for section in textractor("https://en.wikipedia.org/wiki/Nasdaq-100"): + if section.startswith("## Components"): + for line in section.split("\n")[4:]: + if line.count("|") > 1: + stocks.append(line.split("|")[2]) + + return stocks + +def sp500(): + """ + Gets a list of stocks on the S&P 500. + + Returns: + S&P 500 stocks + """ + + stocks, textractor = [], Textractor(sections=True) + for section in textractor("https://en.wikipedia.org/wiki/List_of_S%26P_500_companies"): + if "S&P 500 component stocks" in section: + for line in section.split("\n")[4:]: + if line.count("|") > 1: + stock = line.split("|")[1] + stocks.append(re.sub(r"\[(.+?)\].*", r"\1", stock)) + + return stocks + +def stream(): + """ + Yields a list of unique stocks from the Dow Jones Industrial Average, Nasdaq-100 and S&P 500. + + Returns: + stock infos + """ + + # Get stocks for target indexes + dji, ndx, spx = djia(), nasdaq100(), sp500() + + # Get a list of unique stocks from Nasdaq-100 and S&P 500 + stocks = sorted(set(dji + ndx + spx)) + + # Retrieve stock info from yfinance API + tickers = yf.Tickers(" ".join(stocks)) + for stock in stocks: + # Get stock info + data = tickers.tickers[stock].info + + # Get stock indexes + data["stockIndexes"] = [ + index for x, index in enumerate(["Dow Jones Industrial Average", "Nasdaq-100", "S&P 500"]) + if stock in [dji, ndx, spx][x] + ] + + # Index JSON representation. + data["text"] = json.dumps(data) + + yield data.get("shortName", stock), data + +# Build embeddings index +embeddings = Embeddings( + path="intfloat/e5-large", + instructions={"query": "query: ", "data": "passage: "}, + content=True, + graph={"approximate": False, "minscore": 0.7}, +) +embeddings.index(stream()) +embeddings.save("txtai-stocks") diff --git a/seeker/snippet/update_discord b/seeker/snippet/update_discord new file mode 100644 index 00000000..97da1273 --- /dev/null +++ b/seeker/snippet/update_discord @@ -0,0 +1,23 @@ +#date: 2024-08-19T16:59:38Z +#url: https://api.github.com/gists/ee69855ff97df1d7ffdf102d3589bb02 +#owner: https://api.github.com/users/hydr0nium + +#!/bin/bash + +# Downloaded discord file should be a .gz file. Use gunzip to unzip it. After that you can use this tool + +if [ $# -eq 0 ] +then + echo "No path was given!" + echo "Please run: update_discord " + exit 1 +fi + +sudo mv $1 /opt/discord.tar && +cd /opt/ && +sudo tar -xf discord.tar && +sudo rm discord.tar && +sudo mv ./discord ./discord-backup && +sudo rm -r discord-backup && +sudo mv ./Discord ./discord +echo "Finished updating discord. Please restart it" \ No newline at end of file diff --git a/seeker/snippet/upssched-cmd b/seeker/snippet/upssched-cmd deleted file mode 100644 index f60e2cea..00000000 --- a/seeker/snippet/upssched-cmd +++ /dev/null @@ -1,42 +0,0 @@ -#date: 2024-08-15T16:40:06Z -#url: https://api.github.com/gists/28a25b884b37b4118eaefaac49dcaae2 -#owner: https://api.github.com/users/fabrizziosoares - -#! /bin/sh -case $1 in - ONLINE) - logger -t upssched-cmd "UPS on line power" - ;; - ONBATT) - logger -t upssched-cmd "UPS on battery" - ;; - LOWBATT) - logger -t upssched-cmd "UPS battery is low" - ;; - FSD) - logger -t upssched-cmd "UPS forced shutdown in progress. System is going down!" - /usr/bin/osascript -e 'tell app \"System Events\" to shut down' - ;; - COMMOK) - logger -t upssched-cmd "Communications with UPS established" - ;; - COMMBAD) - logger -t upssched-cmd "Communications with UPS lost" - ;; - SHUTDOWN) - logger -t upssched-cmd "Auto logout and shutdown proceeding. Executing graceful shutdown." - /usr/local/sbin/upsmon -c fsd - ;; - REPLBATT) - logger -t upssched-cmd "UPS battery needs to be replaced" - ;; - NOCOMM) - logger -t upssched-cmd "UPS is unavailable" - ;; - NOPARENT) - logger -t upssched-cmd "upsmon parent process died - shutdown impossible" - ;; - *) - logger -t upssched-cmd "Unrecognized UPS command: $1" - ;; -esac \ No newline at end of file diff --git a/seeker/snippet/worklog.py b/seeker/snippet/worklog.py new file mode 100644 index 00000000..0d78962e --- /dev/null +++ b/seeker/snippet/worklog.py @@ -0,0 +1,83 @@ +#date: 2024-08-19T17:10:50Z +#url: https://api.github.com/gists/61b0e6a685ffd9cd09bf978565e7f7f7 +#owner: https://api.github.com/users/rednafi + +from datetime import datetime, timedelta +from collections.abc import Iterator +from dataclasses import dataclass +import logging + +import logging + +# Set up logging +logger = logging.getLogger(__name__) +logger.setLevel(logging.INFO) +handler = logging.StreamHandler() +formatter = logging.Formatter("%(asctime)s - %(levelname)s - %(message)s") +handler.setFormatter(formatter) +logger.addHandler(handler) + + +@dataclass(slots=True) +class WeekLog: + """Dataclass to store the worklog data for a week.""" + + week_number: int + start_of_week: str + end_of_week: str + days_of_week: list[str] + + +def generate_weeklogs(year: int) -> Iterator[WeekLog]: + """Generates a worklog for the given year, yielding each week's data as a WeekLog object.""" + + first_day_of_year = datetime(year, 1, 1) + first_monday = first_day_of_year + timedelta(days=(7 - first_day_of_year.weekday()) % 7) + + current_day = first_monday + week_number = first_monday.isocalendar()[1] + days_of_week = ("Monday", "Tuesday", "Wednesday", "Thursday", "Friday") + + while current_day.year == year: + start_of_week = current_day.strftime("%Y-%m-%d") + end_of_week = (current_day + timedelta(days=4)).strftime("%Y-%m-%d") + + yield WeekLog( + week_number=week_number, start_of_week=start_of_week, end_of_week=end_of_week, days_of_week=days_of_week + ) + + current_day += timedelta(weeks=1) + week_number += 1 + + +def export_worklog_to_markdown(weeklogs: Iterator[WeekLog], filename: str) -> None: + """Exports the generated worklog to a markdown file with the appropriate formatting.""" + + logger.info(f"Exporting worklog to {filename}") + with open(filename, "w") as file: + # Write the main header + file.write("# Worklog\n\n") + + # Process each week's data + for week in weeklogs: + # Write the week header + week_num = week.week_number + start_of_week = week.start_of_week + end_of_week = week.end_of_week + days_of_week = week.days_of_week + + file.write(f"## Week {week_num} [{start_of_week} - {end_of_week}]\n\n") + + # Write each day of the week + for day in days_of_week: + file.write(f"- **{day}**\n") + + file.write("\n") + + logger.info("Worklog exported successfully!") + + +if __name__ == "__main__": + year = 2024 + worklog = generate_weeklogs(year) + export_worklog_to_markdown(worklog, f"worklog_{year}.md")