Skip to content

Instantly share code, notes, and snippets.

View localredhead's full-sized avatar

Levi Strope localredhead

View GitHub Profile
@localredhead
localredhead / tz_from_dst_using_offset
Created September 27, 2012 00:23
Adjust for DST when finding timezone using UTC_OFFSET
#where OFFSET is seconds
ActiveSupport::TimeZone.all.find { |z| ((z.now.dst? && z.utc_offset == OFFSET-3600) || (!z.now.dst? && z.utc_offset == OFFSET))}
@localredhead
localredhead / emacs.el
Created October 11, 2012 20:44
emacs config WIP. Combo Emacs Start Kit + Emacs Kicker
;; emacs kicker --- kick start emacs setup
;; Copyright (C) 2010 Dimitri Fontaine
;;
;; Author: Dimitri Fontaine <dim@tapoueh.org>
;; URL: https://github.com/dimitri/emacs-kicker
;; Created: 2011-04-15
;; Keywords: emacs setup el-get kick-start starter-kit
;; Licence: WTFPL, grab your copy here: http://sam.zoy.org/wtfpl/
;;
;; This file is NOT part of GNU Emacs.
@localredhead
localredhead / gist:4063686
Created November 13, 2012 03:00
check disk usage for large files to be deleted
du -h / | grep ^[0-9.]*G
@localredhead
localredhead / scratch
Created November 17, 2012 01:10
custom preferences
Android applications can maintain their own internal preferences (and allow them to be modified by users) with very little coding. In fact, you don't even need to write an code to explicitly save these preferences, it's all handled automatically!
Create a new Android project, with an intial activity title Main.
Create two more activities:
ShowPrefs, which extends Activity
Set Prefs, which extends PreferenceActivity
Add these two to your AndroidManifest.xml file:
@localredhead
localredhead / state_machine_class.rb
Last active December 14, 2015 16:28
State machine setup.
class SomeClass < ActiveRecord::Base
STATES = {:is_valid => 0, :needs_review => 1, :reviewed => 2, :is_invalid => 3}
def initialize(*args)
super(*args)
end
attr_accessible :state
@localredhead
localredhead / tmux_sess
Created May 11, 2013 00:38
TMUX setup to launch emacs --daemon (OSX)
1. create .sh file, add this to it:
#!/bin/sh
/Applications/Emacs.app/Contents/MacOS/Emacs --daemon
2. Use platypus to wrap the .SH file as a .app.
3. Add .app to Login Items
4. Edit .tmux.conf and add "new session"
@localredhead
localredhead / .irbrc
Created May 18, 2013 02:00
pbcopy for irb sessions.
IRB.conf[:PROMPT_MODE] = :DEFAULT
def pbcopy(input)
str = input.to_s
IO.popen('pbcopy', 'w') { |f| f << str }
str
ENV["WATCHR"] = "1"
system 'clear'
def growl(message)
growlnotify = `which growlnotify`.chomp
title = "Watchr Test Results"
puts message
image = message.match(/\s0\s(errors|failures)/) ? "~/.watchr_images/passed.png" : "~/.watchr_images/failed.png"
options = "-w -n Watchr --image '#{File.expand_path(image)}' -m '#{message}' '#{title}'"
system %(#{growlnotify} #{options} &)
#!/usr/bin/env bash
uninstall() {
list=`gem list --no-versions`
for gem in $list; do
gem uninstall $gem -aIx
done
gem list
gem install bundler
}
-------- request JSON ---------
"build": {
"monogram": {
"name": "Monogram",
"id": 33
},
"placket": {
"name": "Placket",
"id": 18
},