Skip to content

Instantly share code, notes, and snippets.

Christian Genco christiangenco

View GitHub Profile
@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
@christiangenco
christiangenco / vietnamese_puzzle.rb
Last active Jan 8, 2017
This Problem Stumped Vietnamese Students - Solution To Viral Puzzler https://www.youtube.com/watch?v=WiB2_dXSSMg
View vietnamese_puzzle.rb
# runs in about 10s on my 1.1GHz MacBook.
equation = "x+13*x/x+x+12*x-x-11+x*x/x-10==66".gsub("x", "%.1f")
puts (1..9).to_a.permutation.map{|nums|equation%nums}.select{|eq| eval(eq)}
View wma to mp3 example.sh
mplayer -vo null -vc dummy -af resample=44100 -ao pcm -ao pcm:waveheader file.wma && lame -m s audiodump.wav -o file.mp3 && rm audiodump.wav
@christiangenco
christiangenco / download_tapeacall.rb
Last active Feb 20, 2017
Export all recordings from TapeACall
View download_tapeacall.rb
require 'json'
require 'time'
recordings = JSON.parse(ARGF.read)
recordings.each{|recording|
timestamp = Time.at(recording["created"].to_i).strftime("%Y-%m-%d %H.%M.%S")
destination = File.expand_path("#{timestamp}.mp3")
cmd = "curl \"#{recording["url"]}\" > \"#{destination}\""
puts cmd
@christiangenco
christiangenco / add_to_reading_list
Created Feb 17, 2016
command line utility to add urls to the Safari iOS and Mac reading list
View add_to_reading_list
#!/usr/bin/env osascript
-- usage:
-- add_to_reading_list "http://google.com" "http://yahoo.com"
on run argv
repeat with arg in argv
tell app "Safari" to add reading list item (arg as text)
end repeat
end run
@christiangenco
christiangenco / timecards.rb
Last active Jul 9, 2016
process EMC timecards
View timecards.rb
require 'time'
class Float
def round_to(x)
(self * 10**x).round.to_f / 10**x
end
def ceil_to(x)
(self * 10**x).ceil.to_f / 10**x
end
You can’t perform that action at this time.