Skip to content

Instantly share code, notes, and snippets.

@henrik
henrik / hash_deep_diff.rb
Created July 14, 2009 08:38
Recursively diff two Ruby hashes.
# Recursively diff two hashes, showing only the differing values.
# By Henrik Nyh <http://henrik.nyh.se> 2009-07-14 under the MIT license.
#
# Example:
#
# a = {
# "same" => "same",
# "diff" => "a",
# "only a" => "a",
# "nest" => {
@ghoseb
ghoseb / ns-cheatsheet.clj
Last active April 11, 2024 05:28 — forked from alandipert/ns-cheatsheet.clj
Clojure ns syntax cheat-sheet
;;
;; NS CHEATSHEET
;;
;; * :require makes functions available with a namespace prefix
;; and optionally can refer functions to the current ns.
;;
;; * :import refers Java classes to the current namespace.
;;
;; * :refer-clojure affects availability of built-in (clojure.core)
;; functions.
# QUELLE: http://wiki.hetzner.de/index.php/Sensors.conf
#
# /etc/sensors3.conf von Debian / lm-sensors 3.0.2
# ================================================
#
# sample configuration for the Fintek f71882fg for MSI X58 Pro (7522-040R,
# like seen in Hetzner's EQ6 servers). To load the driver module, append a
# single line (without the #) to /etc/modules:
# f71882fg
@code-later
code-later / gist:719848
Created November 29, 2010 11:25
Load a project specific .irbrc in your Rails 3 project
# Add this method the MyApp::Application class (in config/application.rb)
def load_console(sandbox=false)
super
project_specific_irbrc = File.join(Rails.root, ".irbrc")
puts "Loading project specific .irbrc ..."
load(project_specific_irbrc) if File.exists?(project_specific_irbrc)
end
@bobthecow
bobthecow / tab.bash
Last active November 10, 2023 08:47
Open new Terminal tabs from the command line
#!/bin/bash
#
# Open new Terminal tabs from the command line
#
# Author: Justin Hileman (http://justinhileman.com)
#
# Installation:
# Add the following function to your `.bashrc` or `.bash_profile`,
# or save it somewhere (e.g. `~/.tab.bash`) and source it in `.bashrc`
#
@danlynn
danlynn / gist:809103
Created February 3, 2011 05:54
Grouping a list of strings by similarity using Levenshtein string distance
# The Levenshtein distance between two strings is defined as the minimum number
# of edits needed to transform one string into the other, with the allowable
# edit operations being insertion, deletion, or substitution of a single character.
#
# see:
# http://en.wikipedia.org/wiki/Levenshtein_distance
# http://en.wikibooks.org/wiki/Algorithm_implementation/Strings/Levenshtein_distance#Ruby
# https://github.com/threedaymonk/text/blob/master/lib/text/levenshtein.rb
@jpmckinney
jpmckinney / dokdok-httparty.rb
Created February 10, 2011 23:25
DokDok API access with HTTParty
# blog post: http://blog.slashpoundbang.com/post/3230523402/use-the-dokdok-api-from-ruby
require 'base64'
require 'openssl'
require 'httparty'
class DokDok
include HTTParty
base_uri 'api.dokdok.com'
@jacobian
jacobian / models.py
Created February 15, 2011 18:11
An example of using many-to-many "through" to augment m2m relationships. See http://www.quora.com/How-do-you-query-with-a-condition-on-a-ManyToMany-model-in-Django for context.
from django.db import models
class Person(models.Model):
name = models.CharField(max_length=200)
groups = models.ManyToManyField('Group', through='GroupMember', related_name='people')
class Meta:
ordering = ['name']
def __unicode__(self):
@ianbishop
ianbishop / MessagePassing1.rb
Created March 23, 2011 22:30
Simple message passing example in Ruby (1)
class Repeater
@@subscribers = []
# Add the new subscriber to our list of subscribers
def subscribe(newSubscriber)
@@subscribers << newSubscriber
end
# Send the message to all of our subscribers
def broadcast(message)
#!/usr/bin/env ruby
#
# Originally written by http://redartisan.com/tags/csv
# Added and minor changes by Gavin Laking
# Rewritten by Andrew Bennett for Ruby 1.9
#
# Usage: ruby csv_to_fixture.rb file.csv [--json]
#
# "id","name","mime_type","extensions","icon_url"
# "1","unknown","unknown/unknown","||","/images/icon/file_unknown.gif"