Skip to content

Instantly share code, notes, and snippets.

@christiangenco
christiangenco / process.rb
Created Apr 15, 2021
Crop a bunch of burst photos and stitch them together into a video
View process.rb
paths = Dir.glob("*.jpg")
`mkdir -p cropped`
paths.sort.each_with_index{|path, i|
cropped_path = "cropped/#{i.to_s.rjust(2, "0")}.jpg"
starting_width = 3834
starting_height = 5751
width = starting_width
height = starting_width
@christiangenco
christiangenco / Example.js
Created Feb 27, 2021
React hook for mousetrap
View Example.js
import React from "react";
import useMousetrap from "./hooks/useMousetrap";
export default function Example(){
useMousetrap({
a: () => console.log("you pressed a"),
"ctrl+space": () => console.log("you pressed ctrl+space");
});
return "lol hi";
}
@christiangenco
christiangenco / ViewController.swift
Created Dec 30, 2020
Minimal macOS Swift app to show webcam video in a custom NSView
View ViewController.swift
import Cocoa
import AVFoundation
// inspiration: https://www.youtube.com/watch?v=1_PUdhLQsZQ
class ViewController: NSViewController {
@IBOutlet weak var videoView: NSView!
private var cameraSession = AVCaptureSession()
private var camera: AVCaptureDevice!
@christiangenco
christiangenco / OpenJournalReferencedOnThisLine.py
Created Oct 10, 2020
Sublime Text 3 plugin to run a terminal command based on the contents of the line that the cursor is on
View OpenJournalReferencedOnThisLine.py
import sublime
import sublime_plugin
import re
import os
class OpenJournalReferencedOnThisLineCommand(sublime_plugin.TextCommand):
def run(self, edit):
region = self.view.sel()[0]
line_range = self.view.line(region)
line = self.view.substr(line_range)
@christiangenco
christiangenco / MarkdownCheckboxes.py
Created Jun 3, 2020
Sublime Text 3 plugin to toggle and timestamp markdown todo checkboxes
View MarkdownCheckboxes.py
# ~/.config/sublime-text-3/Packages/User/MarkdownCheckboxes.py
import sublime, sublime_plugin
import re
from time import strftime
def now():
return strftime("%Y-%m-%dT%H:%M:%S")
timestampRegex = r"\s*\(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\)"
@christiangenco
christiangenco / scrape_wikipedia_table.js
Created Nov 6, 2018
Download a wikipedia table as a .json file. Requires jquery and artoo.
View scrape_wikipedia_table.js
function tableToJson(table) {
var data = [];
// first row needs to be headers
var headers = [];
for (var i=0; i<table.rows[0].cells.length; i++) {
headers[i] = table.rows[0].cells[i].innerHTML.toLowerCase().replace(/ /gi,'');
}
// go through cells
@christiangenco
christiangenco / organize_mp3s.rb
Created Oct 18, 2018
Organize and rename a folder of mp3s by album and title
View organize_mp3s.rb
# usage:
# ruby organize_mp3s.rb /path/to/mp3/directory/
require 'shellwords'
def clean filename
return "" unless filename
filename.gsub(/[^0-9A-Za-z.\- ]/, '_')
end
@christiangenco
christiangenco / App.js
Created Jan 16, 2018
fbr.teachable.com "Delete A Document From The Firestore"
View App.js
import React, { Component } from "react";
import "./App.css";
import { db } from "./firebase";
window.db = db;
class App extends Component {
state = {
title: "Loading...",
@christiangenco
christiangenco / App.js
Last active Jan 16, 2018
fbr.teachable.com "Read Multiple Documents From The Firestore"
View App.js
import React, { Component } from "react";
import "./App.css";
import { db } from "./firebase";
window.db = db;
class App extends Component {
state = {
title: "Loading...",
View pi_monte.rb
def pi_monte(n=100_000)
inside = total = 0
n.times{
x, y = rand*2-1, rand*2-1
d = Math.sqrt(x**2+y**2)
if d < 1
inside += 1
end