Skip to content

Instantly share code, notes, and snippets.

View kevinlinxc's full-sized avatar

Kevin Lin kevinlinxc

View GitHub Profile
@kevinlinxc
kevinlinxc / csvtosheets.py
Created June 7, 2022 06:03
Convert Basic Pitch CSV into MIDI with MIDIUtil
# unsuccessful attempt to convert the basic pitch csv into sheet music. Difficult because converting seconds to beats is difficult
from midiutil.MidiFile import MIDIFile
from csv import reader
import sys
hard_coded_start_time = 1.184217687
def csv_to_midi(csv_path, output_path):
@kevinlinxc
kevinlinxc / seed.sh
Last active June 21, 2022 17:26
Rubygems.org Database Seeding
#!/bin/sh
set -e # exit immediately if any command fails
# Warning:
# Resets the db
# Assumptions:
# This script is run from rubygems.org root directory
# elasticsearch, memcached, and postgresql are running. For me, this meant
# docker run -p 9200:9200 -e "http.host=0.0.0.0" -e "transport.host=127.0.0.1" docker.elastic.co/elasticsearch/elasticsearch:7.10.1
# memcached
@kevinlinxc
kevinlinxc / get_dependencies.rb
Last active August 15, 2022 22:55
Get a list of direct dependencies for a gem using the RubyGems.org API
def get_dependencies(gem_name)
# query rubygems.org api for dependencies of gem_name
# return array of dependencies
# requires uri, net/http, and json
uri = URI("https://rubygems.org/api/v1/gems/#{gem_name}.json")
response = Net::HTTP.get_response(uri)
res = JSON.parse(response.body) if response.is_a?(Net::HTTPSuccess)
res["dependencies"]["runtime"].map { |dep| dep["name"] }
end
@kevinlinxc
kevinlinxc / get_gem_downloads.rb
Last active August 15, 2022 22:55
Get download count for a Ruby gem using the RubyGems.org API
def get_downloads(gem_name, version=nil)
# query rubygems api for total downloads of gem_name for the given version
# return integer of downloads
# if version is nil, return total downloads of the latest version
# requires uri, net/http, and json
if version == nil
uri = URI("https://rubygems.org/api/v1/gems/#{gem_name}.json")
response = Net::HTTP.get_response(uri)
res = JSON.parse(response.body) if response.is_a?(Net::HTTPSuccess)
res["downloads"]
@kevinlinxc
kevinlinxc / bundle_lock_deps.rb
Last active August 15, 2022 22:56
Determine all transitive dependencies of a gem using Bundler
def bundle_lock_deps(gem_name)
# reads Gemfile.lock resolved dependencies and return them in an Array of [name, version] pairs
# requires bundler
delete_gemfiles
write_gem_to_gemfile(gem_name)
raise "bundle lock errored" unless system("bundle lock > /dev/null")
# read Gemfile.lock and return an Array of gem names
parser = Bundler::LockfileParser.new(Bundler.read_file('Gemfile.lock'))
output = []
@kevinlinxc
kevinlinxc / gem_dependency_text_dumps.md
Last active August 16, 2022 02:59
Example of the output from the gem dependency investigation
rails-html-sanitizer:
  racc-1.6.0
signet:
  faraday-net_http-3.0.0
  ruby2_keywords-0.0.5
rails-dom-testing:
  racc-1.6.0
rest-client:
 http-accept-1.7.0
@kevinlinxc
kevinlinxc / gem_dependency_paths_printout.md
Last active August 16, 2022 19:43
Gem dependency paths printout example
googleauth:
  faraday-net_http:
    googleauth→faraday→faraday-net_http
    googleauth→signet→faraday→faraday-net_http
  memoist:
    googleauth→memoist
  os:
    googleauth→os
 ruby2_keywords: 
@kevinlinxc
kevinlinxc / dfs.rb
Created August 16, 2022 00:12
Ruby depth-first-search function for blog post
def dfs(start, target)
paths = []
dfs_helper(start, target, [], paths)
paths
end
# note, no cyclic graphs allowed in dependencies, so no visited set needed
def dfs_helper(start, target, path, paths)
path << start
@graph[start].each do |node|
@kevinlinxc
kevinlinxc / swain.py
Last active October 14, 2023 23:21
Python functions used for Swain healing video: https://streamable.com/7041mg
"""
Code used to make Swain video wit healing annotation. Nothing special, just manual frame annotation (30 mins).
CV would have been over-engineering IMO.
pip install streamlit
pip install numpy
pip install opencv-python==4.5.5.62
Read the bottom of the code for run instructions.
"""
@kevinlinxc
kevinlinxc / shared_mem_lib.py
Last active October 1, 2023 05:32
Image transfer using shared memory in Python
import numpy as np
from multiprocessing import shared_memory
# Define global dimensions of 1080 video, would need to change this for a different camera resolution
w, h = 1920, 1080
class SharedMemImagePub:
def __init__(self):
# Create a named SharedMemory object