Skip to content

Instantly share code, notes, and snippets.

// ==UserScript==
// @name Stop gif animations on escape
// @namespace http://github.com/johan/
// @description Implements the "stop gif animations on hitting the escape key" feature that all browsers except Safari and Google Chrome have had since forever. Now also for Google Chrome!
// ==/UserScript==
document.addEventListener('keydown', freeze_gifs_on_escape, true);
function freeze_gifs_on_escape(e) {
@fcamel
fcamel / imgHash.py
Created July 21, 2011 13:38
find similar image
#!/usr/bin/python
# source: http://www.reddit.com/r/programming/comments/hql8b/looks_like_it_for_the_last_few_months_i_have_had/c1xkcdd
import glob
import os
import sys
from PIL import Image
EXTS = 'jpg', 'jpeg', 'JPG', 'JPEG', 'gif', 'GIF', 'png', 'PNG'
@fcamel
fcamel / jsindent.pl
Created July 24, 2011 14:52
indent js
#!/usr/bin/perl
use strict;
use warnings;
use JavaScript::Beautifier qw/js_beautify/;
if ($#ARGV != 1) {
print "jsindent <in file> <out file>\n";
@fcamel
fcamel / tree_add_node.c
Created August 8, 2011 03:16
if-else style comparison
// #1
void add_node(Node *node, Node *new_node) {
if (new_node->value <= node->value) {
if (node->left == NULL) {
node->left = new_node;
return;
}
add_node(node->left, new_node);
return;
}
@fcamel
fcamel / pass_or_die.sh
Created September 16, 2011 02:36
Good code snippet to run or die in shell script.
(autoconf --version) < /dev/null > /dev/null 2>&1 || {
echo
echo "You must have autoconf installed to compile $PROJECT."
echo "Install the appropriate package for your distribution,"
echo "or get the source tarball at http://ftp.gnu.org/gnu/autoconf/"
DIE=1
}
autoconf || exit $?
/* Copyright (C) 1991,1992,1996,1997,1999,2004 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Written by Douglas C. Schmidt (schmidt@ics.uci.edu).
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
@fcamel
fcamel / get_google_doc_list.py
Created December 14, 2011 18:10
Get the list of Google Docs
#!/usr/bin/env python
# -*- encoding: utf8 -*-
import getpass
import gdata
import gdata.docs.service
user = raw_input('username: ')
passwd = getpass.getpass('password: ')
@fcamel
fcamel / gist:1477788
Created December 14, 2011 18:16
vim customized keyword
"Custom syntax
hi DATE guifg=green
syn match DATE /\[201\d\/\d\d\/\d\d\]/
hi IMPORTANT guifg=red
syn match IMPORTANT /(\*)/
@fcamel
fcamel / gist:1582222
Created January 9, 2012 09:44
Sum one column
# from http://stackoverflow.com/questions/3096259/bash-command-to-sum-a-column-of-numbers
$ paste -sd+ infile|bc
@fcamel
fcamel / lock_free_queue.cpp
Created June 8, 2012 15:04
Lock-free queue test
/*
# compilation
$ g++ queue.cpp -O2 -g -pthread -o queue_without_lock -DLOCK_FREE
$ g++ queue.cpp -O2 -g -pthread -o queue_with_lock
# execution time
$ time ./queue_with_lock
real 0m0.035s 0m0.153s 0m0.055s
user 0m0.040s 0m0.270s 0m0.070s
sys 0m0.020s 0m0.030s 0m0.030s