Skip to content

Instantly share code, notes, and snippets.

def notify(msg)
system("notify-send", msg)
end
Signal.trap("HUP") {
3.downto(1) { |n| notify("#{n}..."); sleep 1 }
notify("DEATH!")
exit
}
@epitron
epitron / jquery-throttle.js
Created July 5, 2013 19:42
Throttle repeated JavaScript events (good for making your autocomplete not try to query the server on every keystroke). Not by me!
/*!
* jQuery throttle / debounce - v1.1 - 3/7/2010
* http://benalman.com/projects/jquery-throttle-debounce-plugin/
*
* Copyright (c) 2010 "Cowboy" Ben Alman
* Dual licensed under the MIT and GPL licenses.
* http://benalman.com/about/license/
*/
// Script: jQuery throttle / debounce: Sometimes, less is more!
@epitron
epitron / binding-addition.rb
Last active December 19, 2015 20:49
Add bindings together!
class Binding
def +(other)
self.eval do
other.eval do
binding
end
end
end
end
@epitron
epitron / tweet-anagrams.rb
Last active December 22, 2015 13:28
Find tweets that are anagrams of each other.
require 'set'
require 'pp'
require 'date'
require 'pry'
class Index
include Enumerable
def initialize
@epitron
epitron / epitest.rb
Last active December 23, 2015 11:29
A very powerful testing library.
class EpiTest
def self.inherited(base)
at_exit { base.new.run_my_tests_bitch! }
end
class Fail < Exception; end
def assert(thing)
raise Fail.new(caller_locations[0]) unless thing
// ==UserScript==
// @name YouTube: Click a username and see their videos!
// @namespace http://github.com/epitron/
// @version 0.1
// @description When you click a username, instead of seeing that lame youtube user's "summary" page, you get their actual list of videos (sorted by date).
// @include /^https?://(?:www\.)?(?:youtube\.com)/.*/
// @copyright 2013 epitron
// ==/UserScript==
(function() {
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <linux/input.h>
#include <linux/uinput.h>
#define die(str, args...) do { \
@epitron
epitron / rle.rb
Last active December 30, 2015 01:49
Run-length encoding
def rle_regexp(s)
s.scan(/(.)(\1*)/).map {|c, extra| [c, extra.size+1] }
end
def rle_each_char(s)
result = []
last = nil
count = 0
@epitron
epitron / proxy_controller.rb
Created December 13, 2013 19:28
Turn a Rails controller into a web-proxy (web.archive.org-style)
require 'pp'
class ProxyController < ApplicationController
# Example headers:
# {"GATEWAY_INTERFACE"=>"CGI/1.1",
# "PATH_INFO"=>"/proxy/http:/google.com",
# "QUERY_STRING"=>"",
# "REMOTE_ADDR"=>"127.0.0.1",
# "REMOTE_HOST"=>"127.0.0.1",
@epitron
epitron / gist:8130324
Created December 26, 2013 05:59
rubygems 2.2.0.rc.1 is being weird... retrieving the gemspec for every version of json, from 1.5.5 and up, including java versions, until I manually stop it.
$ gem install -V pry-plus coolline
HEAD https://api.rubygems.org/latest_specs.4.8.gz
302 Moved Temporarily
HEAD https://s3.amazonaws.com/production.s3.rubygems.org/latest_specs.4.8.gz
304 Not Modified
HEAD https://api.rubygems.org/specs.4.8.gz
302 Moved Temporarily
HEAD https://s3.amazonaws.com/production.s3.rubygems.org/specs.4.8.gz
304 Not Modified
GET https://api.rubygems.org/quick/Marshal.4.8/json-1.5.5-java.gemspec.rz