Skip to content

Instantly share code, notes, and snippets.

View michaeldwan's full-sized avatar
🍩

Michael Dwan michaeldwan

🍩
View GitHub Profile

Keybase proof

I hereby claim:

  • I am michaeldwan on github.
  • I am michaeldwan (https://keybase.io/michaeldwan) on keybase.
  • I have a public key whose fingerprint is 9445 1A1E 4C2C AB40 38FA 12F9 B6CE EAA6 0F99 C686

To claim this, I am signing this object:

#!/bin/bash
# chkconfig: 2345 98 02
# description: Starts and stops Solr production
# Calculate RAILS_ROOT as 2 directories above the current file
_script_name=`basename $0`
RAILS_ROOT=`pwd`/`echo $0 | sed -e s/$_script_name//`..
RAILS_ENV=$2
set -e
WARNING: enabling "trust" authentication for local connections
You can change this by editing pg_hba.conf or using the -A option the
next time you run initdb.
Success. You can now start the database server using:
/usr/local/bin/postgres -D /usr/local/var/postgres
or
/usr/local/bin/pg_ctl -D /usr/local/var/postgres -l logfile start
class DirtyTrackingArray < Array
attr_accessor :dirty
def initialize
@dirty = false
end
def push(value)
@dirty = true
super
(function($){
$.fn.sticky = function () {
var toolbar = $(this);
var wrapper = $(this).wrap($('<div />', { id : toolbar.attr('id') + '-wrapper'})).parent();
$(this).width(wrapper.width());
wrapper.height($(this).outerHeight());
$(window).bind('scroll resize', function () {
toolbar.toggleClass('follow', !$.fn.sticky.isScrolledIntoView(wrapper));
});
This prints the caller of a method. Useful to see who the hell called a function that shan't be called:
console.debug(arguments.callee.caller.toString());
@michaeldwan
michaeldwan / bundle_helper.rb
Created July 6, 2010 05:39
Snippet to include JQuery from Google in production and locally in dev
module BundleHelper
def javascript_dev(*sources)
output = ""
sources = sources.to_a
sources.each do |pair|
output << javascript_src_tag(Rails.env.development? ? "dev/#{pair[0]}" : pair[1], {})
end
output.html_safe
end
end
>> redis = Redis.new
=> #<Redis client v2.0.3 connected to redis://127.0.0.1:6379/0 (Redis v1.2.6)>
>> redis.smembers('missing')
=> nil
>> redis.sadd('missing', 'hello')
=> true
>> redis.smembers('missing')
=> ["hello"]
@michaeldwan
michaeldwan / grid.sass
Created October 1, 2010 23:12
SASS implementation of 960 grid system
$column_width: 30;
$gutter_width: 10;
@mixin container($columns) {
margin-left: auto;
margin-right: auto;
width: #{($columns * ($column_width + $gutter_width))}px;
}
@mixin alpha-column {
@michaeldwan
michaeldwan / profile.js
Created March 18, 2011 20:51
Simple Javascript function profiling
// Pass a function to profile and optionally the number of times to run
function profile(test, times) {
var start = new Date().getTime();
if (times === undefined) {
times = 100;
}
for (i = 0; i < times; ++i) {
test();
};