Skip to content

Instantly share code, notes, and snippets.

View minhajuddin's full-sized avatar
⌨️
Beep boop, beep boop

Khaja Minhajuddin minhajuddin

⌨️
Beep boop, beep boop
View GitHub Profile
# with multiple collections + commands for renaming back the collections
require 'mongo'
# Stop writing to your database.
# Then, for each collection:
# Specify the DB and COLLECTION you want to convert.
# Will insert all modified documents into a new collection
# called 'new_' + old_collection_name.
# Then you can delete the old collection and rename the new one
task :spec do
require "rspec/core/rake_task"
RSpec::Core::RakeTask.new(:client) do |t|
t.pattern = "spec/**/*_spec.rb"
end
end
ctrl-z
bg
touch /tmp/stdout
touch /tmp/stderr
gdb -p $!
# In GDB
p dup2(open("/tmp/stdout", 1), 1)
p dup2(open("/tmp/stderr", 1), 2)
#trace mongo in RPM
Mongo::Collection.class_eval do
include NewRelic::Agent::MethodTracer
add_method_tracer :find
add_method_tracer :find_one
add_method_tracer :find_and_modify
add_method_tracer :update
add_method_tracer :insert
add_method_tracer :save
add_method_tracer :remove
ENV["WATCHR"] = "1"
system 'clear'
def growl(message)
growlnotify = `which growlnotify`.chomp
title = "Watchr Test Results"
image = message.include?('0 failures, 0 errors') ? "~/.watchr_images/passed.png" : "~/.watchr_images/failed.png"
options = "-w -n Watchr --image '#{File.expand_path(image)}' -m '#{message}' '#{title}'"
system %(#{growlnotify} #{options} &)
end
@minhajuddin
minhajuddin / gist:1043322
Created June 23, 2011 19:03 — forked from dhh/gist:1014971
Use concerns to keep your models manageable
# autoload concerns
module YourApp
class Application < Rails::Application
config.autoload_paths += %W(
#{config.root}/app/controllers/concerns
#{config.root}/app/models/concerns
)
end
end
@minhajuddin
minhajuddin / Procfile
Created June 27, 2011 18:58 — forked from czottmann/Procfile
Example of a Foreman/Capistrano/upstart setup
worker: QUEUE=* bundle exec rake environment resque:work
scheduler: bundle exec rake environment resque:scheduler
@minhajuddin
minhajuddin / .bashrc
Created July 5, 2011 07:17 — forked from sborsje/.bashrc
Switch projects
PROJECT_PARENT_DIRS[0]="$HOME/code"
for PARENT_DIR in ${PROJECT_PARENT_DIRS[@]} ; do
if [ -d "$PARENT_DIR" ]; then
for PROJECT_DIR in $(/bin/ls $PARENT_DIR); do
if [ ! -z `which $PROJECT_DIR` ]; then
continue # don't set alias if there is something already a command on the path with the same name
fi
if [ -d "$PARENT_DIR/$PROJECT_DIR" ]; then
alias "$PROJECT_DIR"="cd $PARENT_DIR/$PROJECT_DIR"
@minhajuddin
minhajuddin / Prelude.cs
Created July 18, 2011 09:19 — forked from anonymous/Prelude.cs
Oh, you poor, poor imperative developers...
/* Prelude.cs : What happens when a haskell programmer learns C#.
Copyright (c) 2011 Clark Gaebel
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
@minhajuddin
minhajuddin / Hash.from_xml using Nokogiri
Created September 8, 2011 03:24 — forked from dimus/Hash.from_xml using Nokogiri
Adding Hash.from_xml method using Nokogiri
# USAGE: Hash.from_xml:(YOUR_XML_STRING)
require 'nokogiri'
# modified from http://stackoverflow.com/questions/1230741/convert-a-nokogiri-document-to-a-ruby-hash/1231297#1231297
class Hash
class << self
def from_xml(xml_io)
begin
result = Nokogiri::XML(xml_io)
return { result.root.name.to_sym => xml_node_to_hash(result.root)}