Skip to content

Instantly share code, notes, and snippets.

View earlonrails's full-sized avatar

Kevin Krauss earlonrails

  • Disney Streaming
  • San Francisco
View GitHub Profile
@earlonrails
earlonrails / geolocation.js
Created February 29, 2012 16:14
Get the latitude and longitude of the browser, using geolocation.
navigator.geolocation.getCurrentPosition(function(position) {
alert("lat" + position.coords.latitude + " long" + position.coords.longitude);
});
@earlonrails
earlonrails / hsh.rb
Last active October 1, 2015 19:58
Some simple hash methods for ruby 1.9.x
# simple hash methods for ruby 1.9.x
# maybe for rails object attributes :D
# for creating a similar user date time as a string can break in some cases or maybe just skip things you don't need
# ie:
# attributes = simplify_record(User.first.attributes, [:attributes, :i, :need, :and, :not, :date_time_string])
# User.create(attributes)
def simplify_record(hash, keep)
hash.keep_if { |key| keep.include?(key) }
end
@earlonrails
earlonrails / update_hosts.sh
Last active October 3, 2015 16:08
Use shmux with ruby commands that require rvm
#!/bin/bash
# be sure to load .bash_profile which will load your rvm
shmux -c "source .bash_profile; git pull; bundle install" host1 host2 host3
@earlonrails
earlonrails / album.rb
Created April 25, 2012 16:55
Ignore a column in active record
class Album < ActiveRecord::Base
set_table_name "album"
## --------------------- Ignore columns patch ------
@@ignore_column_pattern = /^column_one|^column_two/
class << self
alias :all_columns :columns
def columns
@columns_filt ||= all_columns.reject { |col| col.name =~ @@ignore_column_pattern }
end
@earlonrails
earlonrails / code_review.rake
Created April 30, 2012 17:17
rake code review task. Parse git diff and git show to generate some html pages which have code changes side by side from left and right branches. Don't pay for code review tools! Don't use crazy tools with databases! Too much overhead!
require 'cgi'
require 'fileutils'
desc 'Generate a code review.'
# Uses rake code_review[master,qa] by default
task :code_review, :left_branch, :right_branch do |cmd, args|
left_branch = ( args[:left_branch] || "master" )
right_branch = ( args[:right_branch] || "qa" )
gp = GitParser.new(left_branch, right_branch)
gp.fancy_full_diff
@earlonrails
earlonrails / morse_decoder.rb
Created May 6, 2012 18:42
Morse decoder for therubygame.com
# morse == ".... . .-.. .--. -- . --- ..- - --- ..-. - .... .. ... .-- . .-.. .-.."
words = morse.split(" ")
letters = []
morse_code_map = { ".-" => :A, "-." => :N,
"-..." => :B, "---" => :O,
"-.-." => :C, ".--." => :P,
"-.." => :D, "--.-" => :Q,
"." => :E, ".-." => :R,
"..-." => :F, "..." => :S,
"--." => :G, "-" => :T,
@earlonrails
earlonrails / splat.rb
Last active February 19, 2020 02:00
Iterm function which will create multiple tabs in a grid or vertical panes and execute the command or commands passed to it. ie. splat "ping google.com" "ping cnn.com" "ping twitter.com" "ping yahoo.com"
#!/usr/local/bin/ruby
require 'shellwords'
args = ARGV
size = args.size
tab_open = 'tell i term application "System Events" to keystroke "t" using {command down}'
v_pane_open = 'tell i term application "System Events" to keystroke "d" using {command down}'
h_pane_open = 'tell i term application "System Events" to keystroke "d" using {command down, shift down}'
go_left_one_pane = 'tell i term application "System Events" to key code 123 using {command down, option down}'
script_builder = Proc.new do |tell, command|
@earlonrails
earlonrails / JQuerytagNameClassNameId.js
Created May 12, 2012 07:35
output tagName and className and id using jquery.
$('*').click(function(e){
var tagId = $(this).attr("id");
if (tagId) {
myCssSelector = this.tagName + "#" + tagId;
var myClassName = $(this).attr("class");
if (myClassName) {
myCssSelector = myCssSelector + "." + myClassName;
} else {
myCssSelector = myCssSelector + " ";
}
@earlonrails
earlonrails / printy_mc_scrum.rb
Created May 20, 2012 01:22
Use jira rest api to make pdf's of your current sprint. Using https.
require "rubygems"
require "net/http"
require "net/https"
require "prawn"
require "json"
require "uri"
# ruby printy_mc_scrum.rb "https://my.jira.com/rest/api/latest/issue/" BKLOG-1234 userName password
# PrintyMcScrum.new("https://my.jira.com/rest/api/latest/issue/", "BKLOG-1728", "userName", "password")
class PrintyMcScrum
attr_accessor :pbi_s, :args, :user, :password, :issue_url
@earlonrails
earlonrails / opensips.rb
Created June 27, 2012 02:04
homebrew formula for opensips. opensips fix your crappy Makefiles! Returns bad exit codes when there are no errors.
require 'formula'
class Opensips < Formula
homepage ''
url 'http://opensips.org/pub/opensips/1.5.3/src/opensips-1.5.3-notls_src.tar.gz'
sha1 'c7f89f44a6c2637fd53fd695c6ccef27daa69621'
fails_with :clang do
build 318
cause "Segfault while linking"