Skip to content

Instantly share code, notes, and snippets.

@mnutt
mnutt / Instrument Anything in Rails 3.md
Created September 6, 2010 06:50
How to use Rails 3.0's new notification system to inject custom log events

Instrument Anything in Rails 3

With Rails 3.0 released a few weeks ago I've migrated a few apps and I'm constantly finding useful new improvements. One such improvement is the ability to log anything in the same way that Rails internally logs ActiveRecord and ActionView. By default Rails 3 logs look slightly spiffier than those produced by Rails 2.3: (notice the second line has been cleaned up)

Started GET "/" for 127.0.0.1 at Mon Sep 06 01:07:11 -0400 2010
  Processing by HomeController#index as HTML
  User Load (0.2ms)  SELECT `users`.* FROM `users` WHERE (`users`.`id` = 3) LIMIT 1
  CACHE (0.0ms)  SELECT `users`.* FROM `users` WHERE (`users`.`id` = 3) LIMIT 1

Rendered layouts/_nav.html.erb (363.4ms)

@karmi
karmi / tagcloud.sh
Last active September 4, 2017 02:01
Simple tag cloud with ElasticSearch `terms` facet
# (Re)create the index
curl -X DELETE "http://localhost:9200/tagcloud"
curl -X PUT "http://localhost:9200/tagcloud"-d '{
"settings" : {
"index" : {
"number_of_shards" : 1,
"number_of_replicas" : 0
}
}
}'
@aero
aero / demacboogi.pl
Created July 25, 2011 07:44
Rename MacOS X NFD hangule to NFC
#!/usr/bin/env perl
# 사용법
# perl demacboogi.pl *.zip #zip파일만 변환
# perl demacboogi.pl #모든파일 변환
use 5.010;
use strict;
use warnings;
use Encode qw/encode decode/;
use Unicode::Normalize qw/compose/;
use File::Copy;
@prisoner
prisoner / consistent_hashr.rb
Created July 28, 2011 18:05
A Consistent Hashing implementation for Ruby
require 'zlib'
module ConsistentHashr
@circle = {}
@number_of_replicas = 20
##
# Computes a key
def self.hash_key(key)
Zlib.crc32("#{key}")
javascript:(function(){script=document.createElement('script');script.src='http://dict.bing.com.cn/cloudwidget/Scripts/Generated/BingTranslate_Hover_Phrase_Selection_ShowIcon.js';script.onload=INIT;document.body.appendChild(script);})();function INIT(){BingCW.Init({MachineTranslation:true,WebDefinition:true});}
@stackdump
stackdump / gist:1479007
Created December 14, 2011 23:07 — forked from bkimble/gist:1365005
List local memcached keys using Ruby
#!/usr/bin/env ruby
require 'net/telnet'
cache_dump_limit = 100
localhost = Net::Telnet::new("Host" => "localhost", "Port" => 11211, "Timeout" => 3)
slab_ids = []
localhost.cmd("String" => "stats items", "Match" => /^END/) do |c|
matches = c.scan(/STAT items:(\d+):/)
slab_ids = matches.flatten.uniq
end
@plexus
plexus / svn_short_log
Created December 16, 2011 09:01
svn log, one line per commit
#!/usr/bin/awk -f
# Convert the "svn log" output into a one liner format, which is easier to grep
# or use in scripts. Pipe "svn log" into this script
# When we get a line that starts with a revision number, put the data in variables
/^r[0-9]+/ {
rev=$1
user=$3
date=$5
@okitan
okitan / backtrace_silencers.rb
Created December 27, 2011 13:04
Rails formatted backtrace on logger (tested in Rails 3.0.10)
Rails.backtrace_cleaner.remove_silencers!
Rails.backtrace_cleaner.add_silencer { |line| line =~ /spec/ }
module ActiveSupport
class BacktraceCleaner
def clean_with_format(backtrace, kind = :silent)
filtered = clean_without_format(backtrace, kind)
splits = filtered.map do |line|
@ticean
ticean / SVN_Git_Mirror.md
Created January 3, 2012 21:14
SVN Git Mirror

Create Git Mirror from SVN Repository

This guide will demonstrate how to mirror an SVN into a Git repo. You're the target audience if you're an SVN user, just getting started with Git and need to coax your project team over to Git.

The branching scenario has been simplified for clarity.

References

@epitron
epitron / ansi2html.rb
Created January 28, 2012 10:02
Convert ANSI to HTML
require 'epitools'
class State
attr_accessor :fore, :back, :attrs
COLORS = [:black, :red, :green, :yellow, :blue, :magenta, :cyan, :white]
ATTRS = {
0 => :reset,