Skip to content

Instantly share code, notes, and snippets.

View kylewelsby's full-sized avatar
🎯
Focusing

Kyle Welsby kylewelsby

🎯
Focusing
View GitHub Profile
<%- flash.each do |name, msg| -%>
<%= content_tag :div, msg , :id => "flash", :class => "flash_#{name}" %>
<%- end -%>
@kylewelsby
kylewelsby / .bash_alias
Created October 1, 2010 12:00
My terminal environment setup
# ---------------
# .bash_alias
# ---------------
alias lock='/System/Library/CoreServices/"Menu extras"/User.menu/Contents/Resources/CGSession -suspend' # Lock Computer screen
alias rpass='touch tmp/restart.txt; echo "Passenger Server Restarted"' # Restart ModRails Passenger
alias coffee="say COFFEE TIME"
alias cf='cd ~/Code' # Code folder
alias cwd='pwd | pbcopy' # Copy folder directory to ClipBoard
alias memory='top -o vsize' # System Memory Stats
@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
@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 / 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 / Gemfile
Created October 2, 2011 14:31
OAuth2 refresh_token testing
group :test do
...
gem 'timecop'
...
end
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 / 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
}
@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 / 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"