Skip to content

Instantly share code, notes, and snippets.

View kylewelsby's full-sized avatar
🏠
Working from home

Kyle Welsby kylewelsby

🏠
Working from home
View GitHub Profile
@kylewelsby
kylewelsby / clean.sh
Created January 20, 2012 08:51
Deploying Heroku Safe Style
#!/bin/bash
# This tool checks if there are any uncommitted changes in the current git branch.
# If it finds any uncommited changes it exits with an error.
# We use it to prevent pushing dirty changes to production.
clean=$(git status | grep "nothing to commit (working directory clean)")
if [ -z "$clean" ]; then
echo There are uncommitted changes.
exit 1
else
@kylewelsby
kylewelsby / startup.sh
Created January 5, 2012 17:46
Start EVERYTHING!
#!/bin/sh
sudo /usr/local/sbin/nginx;
sudo apachectl start
mysql.server start;
pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start
exit;
@kylewelsby
kylewelsby / install_global_guard.rb
Created December 7, 2011 12:32
Install Guard-RSpec to all RMV Rubies
#!/usr/bin/ruby env
guardfile = <<-'END'
def determine_rspec_version
if File.exist?("#{Dir.pwd}/spec/spec_helper.rb")
File.new("#{Dir.pwd}/spec/spec_helper.rb").read.include?("Spec::Runner") ? 1 : 2
elsif bundler?
# Allow RSpactor to be tested with RSpactor (bundle show inside a bundle exec)
ENV['BUNDLE_GEMFILE'] = "#{Dir.pwd}/Gemfile"
@kylewelsby
kylewelsby / app.js
Created October 2, 2011 15:51
1Password Save Tab
$(document).ready(function(){
if(!localStorage.lastOpenPage){
localStorage.lastOpenPage = "logins";
}
$("body").addClass(localStorage.lastOpenPage);
$("nav#tabBar ul li").click(function(){
localStorage.lastOpenPage = $(this).attr('id');
$("body").addClass($(this).attr('id'));
}
@kylewelsby
kylewelsby / device.rb
Created October 2, 2011 14:55
How TxtVia Pushes
class Device < ActiveRecord::Base
...
def push_message(message)
case device_type
when "android"
notification = { :registration_id => registration_id,
:data => {
:message_body => message.body,
:message_recipient => message.recipient
}
class Application < ActiveRecord::Base
require 'httparty'
...
def push_message(message)
if self.post_url
post(self.post_url, :body => message)
end
end
end
@kylewelsby
kylewelsby / Gemfile
Created October 2, 2011 14:31
OAuth2 refresh_token testing
group :test do
...
gem 'timecop'
...
end
@kylewelsby
kylewelsby / PusherController.rb
Created August 18, 2011 14:50
Pushing a partial though Pusher
...
def update
@platforms = Platform.find parmas[:id]
#Option 1
Pusher['event'].trigger($Q{$("#box_qa_app_geolocation").html("<%= escape_javascript(render :partial => "/shared", :object => @platform) %>");})
#Option 2
@kylewelsby
kylewelsby / itunes.rb
Created May 20, 2011 09:36
example of osascript chained response.
def trackLocation
%x(osascript -e 'tell app "iTunes"' -e "set trk to current track" -e 'if kind of trk is "MPEG audio stream" then' -e "return address of trk" -e "else" -e "set l to trk's location" -e "return POSIX path of l" -e "end if" -e "end tell").rstrip
end
def trackArtwork
dbid = %x(osascript -e 'tell app "iTunes" to return database id of current track').rstrip
location = "/tmp/iTunesArtwork.pict"
%x(touch #{location})
%x(osascript -e 'tell app "iTunes"' -e 'set aTemp to POSIX file "#{location}" as alias' -e 'set aTrackArtwork to null' -e "set response to null" -e "if (count of artwork of current track) > 0 then" -e "set aTrackArtwork to data of artwork 1 of current track" -e "set fileRef to (open for access aTemp with write permission)" -e "try" -e "set eof fileRef to 512" -e "write aTrackArtwork to fileRef starting at 513" -e "close access fileRef" -e 'set response to "/tmp/iTunesArtwork.pict"' -e "on error" -e "try" -e "close access fileRef" -e "set response to null" -e "end try" -e "en
@kylewelsby
kylewelsby / .rvmrc
Created October 4, 2010 10:07
RVM and Passenger playing nicely
# Each site directory uses its own Gemset and specifies its Ruby version.
rvm use 1.9.2@personal_ictunes --create
passenger start -a 127.0.0.1 -p 8090 -d