Skip to content

Instantly share code, notes, and snippets.

@williamho
williamho / jingle.c
Created December 26, 2012 00:02
Merry Christmas
#include <stdio.h>
main() {
int i;
for (i=0; i<4; i++)
printf("jingle %s\n",(i<3)?"bells":"all the way");
return 0;
}
@williamho
williamho / wordfreq.pl
Created January 10, 2013 04:49
hello pearl
#!/usr/bin/perl
@words = ('hi', 'hihi', 'hello', 'hi', 'hi', 'hihi');
%wordfreq = ();
foreach $w (@words) {
$wordfreq{$w} ++;
}
foreach $w (keys %wordfreq) {
print "$w appears $wordfreq{$w} times\n"
}
@williamho
williamho / Fibonacci.java
Last active May 24, 2020 00:38
Recursive Fibonacci with two threads, written for an assignment. In general, not a good idea.
import java.util.*;
import java.util.concurrent.*;
public class Fibonacci {
public static void main(String[] args) {
int num = 1;
int out = 0;
try {
num = Integer.parseInt(args[0]);
} catch (Exception e) {
@williamho
williamho / Fib.java
Last active December 11, 2015 23:58
Multi-threaded non-recursive fibonacci. Not any more efficient than a single-threaded version.
public class Fib implements Runnable {
int curr=1, prev=1, counter=0, num;
Fib(int num) {
this.num = num;
}
private synchronized void calc() {
try {
System.out.println(Thread.currentThread().getName() + ": " + curr);
int tmp = curr;
@williamho
williamho / rails_course
Created October 25, 2013 21:08
class notes
course.third.io
guard:
foreman: start services e,g., elasticsearch, mysql
dotenv: load variables from .env file into rails environment variables
mailcatcher: useful for debugging mailers
rails admin
association scopes
presenters
@williamho
williamho / referer.rb
Created June 19, 2014 00:02
extract unique referer
require 'json'
file = File.read 'ads_merg_conf.json'
json = JSON.parse file
ir = json.flat_map do |placement, values|
@williamho
williamho / gist:01f8eed009f7db0e35dd
Created July 23, 2014 04:47
gif caption overlay
convert in.gif null: \( -font "../fonts/rounded-mplus-1c-bold.ttf" -gravity South -size 480 -stroke black -fill white -channel RGBA -background transparent -pointsize 30 caption:'text here' \) -layers Composite out.gif
@williamho
williamho / translate.js
Created April 16, 2015 01:15
translate bookmarklet
javascript:(function(){var t=((window.getSelection&&window.getSelection())||(document.getSelection&&document.getSelection())||(document.selection&&document.selection.createRange&&document.selection.createRange().text));var e=(document.charset||document.characterSet);if(t!=''){window.open('http://translate.google.com/translate_t?text='+t+'&hl=en&langpair=auto|en&tbb=1&ie='+e);}else{window.open('http://translate.google.com/translate?u='+escape(location.href)+'&hl=en&langpair=auto|en&tbb=1&ie='+e);};}());
@williamho
williamho / stop-quora.js
Created June 11, 2015 14:45
bookmarklet to remove the signup modal on quora
javascript:(function(){document.querySelector('[id$=modal_signup_wrapper]').remove();}());
@williamho
williamho / beghilosz.scala
Created June 19, 2015 21:05
find words that can be typed by calculator
// usage: `scala beghilosz.scala < /usr/share/dict/words`
object Program {
val mask: Int = toBitmask("beghilosz")
def main(args: Array[String]): Unit = {
val lines: Iterator[String] = io.Source.stdin.getLines()
val filtered: Iterator[String] = lines.filter { (l: String) =>
val b: Int = toBitmask(l)
(b & mask) == b