Skip to content

Instantly share code, notes, and snippets.

View virtualstaticvoid's full-sized avatar

Chris Stefano virtualstaticvoid

View GitHub Profile
# config/initializers/hstore_accessor.rb
# http://www.devmynd.com/blog/2013-3-single-table-inheritance-hstore-lovely-combination
module HstoreAccessor
def self.included(base)
base.extend(ClassMethods)
end
module ClassMethods
def hstore_accessor(hstore_attribute, *keys)
Array(keys).flatten.each do |key|

why ./task.js?

One word: task automation. It's basically zero effort and you can use the ./task.js package manager to handle any repetitive tasks. You can use ./task.js to automate everything with minimum effort.

./task.js provides the structure, order, and authority that you as a developer so desperately crave. ./task.js will also take responsibility for your actions if you need it to. It's what everybody is using now. ./task.js is the new hotness. It's all about ./task.js now, just like that.

This is compared to npm run/bash scripts, which are:

@virtualstaticvoid
virtualstaticvoid / extradrop
Created December 19, 2013 14:10
Run multiple Dropbox accounts at once on Ubuntu
#!/bin/bash
if [ -z "$1" ]
then
echo "No dropbox profile specified" >&2
echo "Usage: $(basename "$0") profile command" >&2
exit 1
fi
fold="$1"
@virtualstaticvoid
virtualstaticvoid / gist:5635155
Last active December 17, 2015 15:59
Get the visible parent of a given element in jQuery
getVisibleParent = (element) ->
parents = element.parent(':visible')
if parents.length == 0
getVisibleParent(element.parent())
else
parents
@virtualstaticvoid
virtualstaticvoid / spec_helper.rb
Last active November 14, 2018 20:22 — forked from pauljamesrussell/spec_helper.rb
RSpec Matchers
# Use: it { should accept_nested_attributes_for(:association_name).and_accept({valid_values => true}).but_reject({ :reject_if_nil => nil })}
RSpec::Matchers.define :accept_nested_attributes_for do |association|
match do |model|
@model = model
@nested_att_present = model.respond_to?("#{association}_attributes=".to_sym)
if @nested_att_present && @reject
model.send("#{association}_attributes=".to_sym,[@reject])
@reject_success = model.send("#{association}").empty?
end
model.send("#{association}").clear
@virtualstaticvoid
virtualstaticvoid / gist:4110001
Created November 19, 2012 10:27 — forked from technoweenie/gist:2155760
track meta data with resque jobs, like when it was queued.
module Resque
def push_with_meta(queue, item)
if item.respond_to?(:[]=)
item[:meta] = {:queued_at => Time.now.to_f}
end
push_without_meta(queue, item)
end
class Job
# Returns a Hash of the meta data related to this Job.
@virtualstaticvoid
virtualstaticvoid / chosen-bootstrap.css
Created June 30, 2012 18:21 — forked from rabu81/chosen-bootstrap.css
overwrite chosen styling to look like bootstrap
/*
* add this to your own css file,
* to overwrite the _chosen_ styling, to look more like bootstrap!
*
* note: for the error part to work, an .error class-name must be added
* to a wrapping DIV, to display the bootstrap error styling. I have
* just use the wrapping .control-group DIV
*
* credit: Rasmus Burkal, @rabu81
*/
@virtualstaticvoid
virtualstaticvoid / databases.rake
Created May 11, 2012 20:41 — forked from wbailey/databases.rake
ActiveRecord migrations outside of Rails
require 'yaml'
require 'logger'
require 'active_record'
namespace :db do
def create_database config
options = {:charset => 'utf8', :collation => 'utf8_unicode_ci'}
create_db = lambda do |config|
ActiveRecord::Base.establish_connection config.merge('database' => nil)
@virtualstaticvoid
virtualstaticvoid / git-reset-modes
Created March 22, 2012 00:15
Resets file modes in Git
#!/bin/bash
git diff --numstat | awk '{if ($1 == "0" && $2 == "0") print $3}' | xargs git checkout HEAD
@virtualstaticvoid
virtualstaticvoid / redis_pubsub_demo.rb
Created March 18, 2012 18:44 — forked from pietern/redis_pubsub_demo.rb
Simple demo to showcase Redis PubSub with EventMachine
# Author: Pieter Noordhuis
# Description: Simple demo to showcase Redis PubSub with EventMachine
#
# Update 7 Oct 2010:
# - This example does *not* appear to work with Chrome >=6.0. Apparently,
# the WebSocket protocol implementation in the cramp gem does not work
# well with Chrome's (newer) WebSocket implementation.
#
# Requirements:
# - rubygems: eventmachine, thin, cramp, sinatra, yajl-ruby