Skip to content

Instantly share code, notes, and snippets.

View jl2's full-sized avatar

Jeremiah LaRocco jl2

View GitHub Profile
@jl2
jl2 / threadpool.cpp
Created March 27, 2011 18:13
Simple thread pool in C++.
#include <stdio.h>
#include <queue>
#include <unistd.h>
#include <pthread.h>
#include <stdlib.h>
// Base task for Tasks
@jl2
jl2 / gtrans.pl
Created March 30, 2011 19:48
Perl command line interface to Google Translate.
#!/usr/bin/perl
# By: Jeremiah LaRocco
# Use translate.google.com to translate between languages.
# Sample run:
# gtrans.pl --to french --from english This is a test
# Ceci est un test
#
use strict;
@jl2
jl2 / gist:928952
Created April 19, 2011 17:31
Use lxml and Python3 to validate XML against a DTD.The DTD can be specified on the command line, or as an optional parameter to the script.
#!/usr/bin/env python3
# Use lxml to validate XML against a DTD
import re
import sys
import os.path
import codecs
from lxml import etree
@jl2
jl2 / wtfops.cpp
Created May 27, 2011 22:40
Stupid operator overloading.
#include <iostream>
class WTF {
public:
WTF() : val(this) { }
WTF* operator->() {
std::cout << "hello ";
return this;
}
WTF &operator*() {
#include <iostream>
#include <vector>
#include <string>
int main(int argc, char *argv[]) {
std::vector<int> bob(1);
bob.push_back(20);
bob.push_back(bob[0]);
for (auto it = bob.begin();
it != bob.end();
@jl2
jl2 / gist:1052564
Created June 29, 2011 00:19
Keyboard shortcuts for creating Pinboard bookmarks in Opera
; Read Later
F9=Go to page,"javascript:{q=location.href;p=document.title;void(t=open('https://pinboard.in/add?later=yes&noui=yes&jump=close&url='+encodeURIComponent(q)+'&title='+encodeURIComponent(p),'Pinboard', 'toolbar=no,width=100,height=100'));t.blur();}"
; With tags
F10=Go to page,"javascript:{q=location.href;if(document.getSelection){d=document.getSelection();}else{d='';};p=document.title;void(open('https://pinboard.in/add?showtags=yes&url='+encodeURIComponent(q)+'&description='+encodeURIComponent(d)+'&title='+encodeURIComponent(p),'Pinboard', 'toolbar=no,width=700,height=600'));}"
@jl2
jl2 / gist:1059206
Created July 1, 2011 19:21
.pythonrc
#!/usr/bin/python3
import os
import sys
import math
import random
from datetime import datetime
@jl2
jl2 / spawndesk.py
Created July 14, 2011 20:04
Launch a windows process on a background desktop so any windows it creates are invisible.
#!/usr/bin/env python3
# Launch an application on a new desktop
# The motivation for this is another script that runs depends.exe in profiling mode.
# When depends.exe profiles the application the application's windows pop-up and get
# in the way. It's really annoying, hence spawndesk.py
import sys
import random
import win32con
@jl2
jl2 / bezdraw.py
Created August 11, 2011 20:14
Draw Bezier curves using Python and PyQt
#!/usr/bin/env python3
import sys
import random
import functools
from PyQt4 import QtGui, QtCore
@functools.lru_cache(maxsize=100)
def factorial(n):
@jl2
jl2 / dud
Created August 29, 2011 04:45
"One liner" to show how disk space is being used in the current directory.
#!/usr/bin/zsh
ls -Q -d . | xargs du -b -- | \
sort -n |\
perl -e 'while (<>) { @p = split; $sz = shift @p;\
printf("%3.2f MB \t@p\n",$sz/(1024*1024)); }'