Skip to content

Instantly share code, notes, and snippets.

@lenary
lenary / gitconfig.ini
Created February 18, 2011 01:21
a special excerpt of my gitconfig
$ git clone github:lenary/guides.git
Cloning into guides...
remote: Counting objects: 255, done.
remote: Compressing objects: 100% (216/216), done.
remote: Total 255 (delta 111), reused 163 (delta 35)
Receiving objects: 100% (255/255), 1.49 MiB | 564 KiB/s, done.
Resolving deltas: 100% (111/111), done.
$ cd guides
$ git remote -v
@unimatrixZxero
unimatrixZxero / lolbash.sh
Created March 22, 2011 10:02
Putting this here to archive it.
# LOL!!1
# Dunno who made this. BUT I LUVZ IT.
alias wtf='dmesg'
alias onoz='cat /var/log/errors.log'
alias rtfm='man'
alias visible='echo'
alias invisible='cat'
alias moar='more'
@rkh
rkh / gist:999120
Created May 30, 2011 16:32
Sinatra Stylesheet Expires
# avoid path traversal attacks and speed up look-up
set :css_files, {}
Dir.glob("#{settings.public}/css/*.css") { |file| settings.css_files[File.basename(file, '.css')] = file }
get "/css/:name.css" do |name|
expires 60*60*24*356*3
send_file setting.css_files[name]
end
@vorushin
vorushin / jquery-csrf.js
Created June 24, 2011 08:51
Small jQuery plugin for adding csrf-token to Ajax/Ajaj requests
$.ajaxSetup({
beforeSend: function(xhr, settings) {
function getCookie(name) {
var cookieValue = null;
if (document.cookie && document.cookie != '') {
var cookies = document.cookie.split(';');
for (var i = 0; i < cookies.length; i++) {
var cookie = jQuery.trim(cookies[i]);
// Does this cookie string begin with the name we want?
if (cookie.substring(0, name.length + 1) == (name + '=')) {
@mattheworiordan
mattheworiordan / rate_limit.js
Created July 15, 2011 14:49
Rate limiting function calls with JavaScript and Underscore.js
/* Extend the Underscore object with the following methods */
// Rate limit ensures a function is never called more than every [rate]ms
// Unlike underscore's _.throttle function, function calls are queued so that
// requests are never lost and simply deferred until some other time
//
// Parameters
// * func - function to rate limit
// * rate - minimum time to wait between function calls
// * async - if async is true, we won't wait (rate) for the function to complete before queueing the next request
@sbp
sbp / data.js
Created July 26, 2011 15:30
jQuery to add "Download" links to PRE and XMP elements
// Download Preformatted Sections
function makeDownloadable() {
// Iconza by Turbolink, Creative Commons BY 3.0 Unported
// http://www.softicons.com/free-icons/designers/turbomilk
var png = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAABxVBMVEUAAACFhYaBgYGHh4iHiImLjI2Gh4eGhodbW1xqa2toaGlpampVVVdhYWJTU1RmZmf///+JiYmkpKR8fHysrKyYmJiHh4e2trZmZmaRkZGIiIiTk5OKiopQUVKDhIZ+fn7ExMTGxsbMzMxhYWFkZGSCgoSGhoaurq5oaGhsbGxubm7JycmAgIJPT1CFhojq6uq+vr6cnJzh4eG1tbWUlJS8vLzn5+eenp69vb1nZ2dlZWXT09Ozs7PAwMCoqKrR0dHPz8/Ozs7i4uLCwsLBwcHZ2dnU1NS3t7eqqqp+f4CmpqaoqKjt7e3Hx8eVlZV7fH58fX6ampqZmZmdnZ3o6Ojl5eXk5OTf39/e3t50dXfd3d2Pj4+NjY2Li4uhoqOOjo6HiIrb29va2tp6enp3d3dub3BwcXOioqKBgYGFhYXv7+/IyMj5+fliYmLKystgYGBwcHBpaWpra21zc3NycnJcXFyQkJBhYmNlZWZtbW3Ly8xcXV6jo6Nra2u/v793eHpjY2N2dnaCg4OLjI7g4OBmZmeCgoLLy8u5ubmEhIRfX2Dc3NzW1tbKysqxsbFPT1Gvr69NTk9NTU9NTk5NTU7m5ua7u7tu8VCdAAAAEHRSTlMAnxe99/evvfC1qKf4+PGpMlfdYgAAAPdJREFUGBlFwYNuRAEQAMCt3e6zz7ZZ27Zt27b9vW2aSzoDySkX/9LSATKKfV9d3eW+y57e/ofH4SQYHRuvjpeUlplp+4JWt
@dkubb
dkubb / gist:1130086
Created August 7, 2011 05:21 — forked from flazz/gist:838163
case with predicates
require 'rubygems'
require 'backports' # aliases Proc#=== to Proc#call
rs = (0..10000).to_a.sample(30)
rs.each do |r|
case r
when lambda { |n| n.zero? } then puts "#{r} is zero"
when lambda { |n| (n % 5).zero? } then puts "#{r} is fiven"
when lambda { |n| (n % 4).zero? } then puts "#{r} is fourven"
@dkubb
dkubb / .rvmrc
Created August 10, 2011 22:44
Web framework Spike
rvm use @$(basename `pwd`) --create
@ralph
ralph / github-flavored-markdown.rb
Created October 20, 2011 11:39
Markdown Processor for Redcarpet version 2, for usage on the command line, in Marked etc. Supports syntax highlighting via Pygments.
#!/usr/bin/env ruby
# Processor for Github flavored markdown, inspired by:
# https://github.com/alampros/Docter/blob/master/bin/github-flavored-markdown.rb
#
# Current version of this script can be found here:
# https://gist.github.com/1300939
#
# Adapted for Redcarpet version 2 by Ralph von der Heyden
# http://github.com/ralph
# http://twitter.com/ralph
@tecoholic
tecoholic / .vimrc
Last active April 19, 2016 04:11
My Vim Setup
"" Vim, not Vi.
" This must be first, because it changes other options as a side effect.
set nocompatible
filetype off
"" General Settings
" Enable syntax highlighting.
syntax on
" Line endings should be Unix-style unless the file is from someone else.