Skip to content

Instantly share code, notes, and snippets.

View Jamedjo's full-sized avatar

James EdJo Jamedjo

View GitHub Profile
@Jamedjo
Jamedjo / custom_plan.rb
Created March 26, 2013 01:37
Zeus command to run asset compilation in development environment with assets group. Usage: `zeus assets some:nested:task' translates to `rake assets:some:nested:task` E.g. `zeus assets precompile` instead of `rake assets:precompile`
require 'zeus/rails'
class CustomPlan < Zeus::Rails
def assets_environment
Bundler.require(:assets)
ENV['RAILS_GROUPS'] = "assets"
end
def assets_run
@Jamedjo
Jamedjo / development
Last active December 15, 2015 19:39
ruby -e 'ENV.each_pair{|k,v|p "#{k}=#{v}"}' cleaned up a bit note that in production I am calling things with bundle exec
"rvm_path=/home/james/.rvm"
"IRBRC=/home/james/.rvm/rubies/ruby-1.9.3-p385-perf/.irbrc"
"rvm_prefix=/home/james"
"_second=2"
"DEFAULTS_PATH=/usr/share/gconf/XMonad.default.path"
"PWD=/home/james/jist-prerelease"
"rvm_version=1.18.21 (stable)"
"GEM_PATH=/home/james/.rvm/gems/ruby-1.9.3-p385-perf@njist325:/home/james/.rvm/gems/ruby-1.9.3-p385-perf@global"
"MY_RUBY_HOME=/home/james/.rvm/rubies/ruby-1.9.3-p385-perf"
"GEM_HOME=/home/james/.rvm/gems/ruby-1.9.3-p385-perf@njist325"
@Jamedjo
Jamedjo / development
Created April 4, 2013 23:55
Extract ENV["RUBY_VERSION"] with gemset by capturing everything after rvm/gems, then everything before a '/' Alternative to http://rubular.com/r/knx27JoODH
1.9.3p385 :010 > GEM_HOME = ENV["GEM_HOME"]
=> "/home/james/.rvm/gems/ruby-1.9.3-p385-perf@njist325"
1.9.3p385 :011 > if GEM_HOME && GEM_HOME =~ %r{rvm/gems/(.+)}
1.9.3p385 :012?> puts $1.sub(/\/.*/, '')
1.9.3p385 :013?> end
ruby-1.9.3-p385-perf@njist325
@Jamedjo
Jamedjo / currency.js
Last active December 18, 2015 02:39
Quick currency detection script I wrote while making http://jamedjo.github.io/Converter/ to test out angularjs
function defaultCurrencyFromLanguage(){
var lang = window.navigator.userLanguage || window.navigator.language;
var symbol = "$";
if(/gb|uk|tr|je|ta|gs|gg|im|sd|sl|vg|cy|eg|fk|gi|lb|sh|ac|ss|sd|sy/i.test(lang)) {
symbol = "£";
}
else if(/me|sk|ea|gf|tf|bl|mf|ie|ee|re|it|mc|si|de|es|at|yt|gp|pm|cy|pt|fr|gr|ic|be|ad|fi|lu|va|mt|sm|mq|nl|ax|cs/i.test(lang)) {
symbol = "€";
}
else if(/cn|jp|fm|sj/i.test(lang)) {
@Jamedjo
Jamedjo / livefyre.js
Last active December 18, 2015 13:09
LiveFyre comments system implemented as an angularjs service. Navigating to to a new page generates a new comment config from the url. Buggy WIP, livefyre appears to be polling a url which is 404 Not Found until it eventually gets created.
myapp.factory('Comments', function ($location) {
var isInitialized = false;
var comments = {};
var getConfig = function(){
var articleId = $location.path();
var defaults = {
articleId: articleId,
collectionMeta: {
articleId: articleId,
@Jamedjo
Jamedjo / Gemfile
Created June 16, 2013 15:09
Sinatra with RSpec config,
source 'https://rubygems.org'
ruby '2.0.0'
gem 'sinatra'
gem 'rspec'
gem 'rack-test'
@Jamedjo
Jamedjo / scrape.rb
Created July 26, 2013 16:04
Scrape top google results for title, meta-description and keywords. Usage: `ruby scrape.rb your search terms go here`
#!/usr/bin/ruby
require 'nokogiri'
require 'open-uri'
#require 'debugger'
require 'cgi'
url = "http://www.google.co.uk/search?q=#{ARGV.join('+')}"
puts url
doc = Nokogiri::HTML(open(url))
# debugger
@Jamedjo
Jamedjo / ga-youtube.js
Last active February 8, 2017 20:43
Google analytics youtube script, with fixes. Standard embed code uses `//` instead of `http://`, so the regex needed updating.
//
//To Track Thy Youtube Upon Google Analytics
//Regardless the number of Players upon thy stage
//Revised and Revisioned to Version 2.1
//Within the March of Two Thousand and Thirteen
//
//Performed by LunaMetrics http://www.lunametrics.com @lunametrics
//and Sayf Sharif @sayfsharif
//
//Who beg thy forgiveness for the lack of the regular expression
@Jamedjo
Jamedjo / gist:6209799
Created August 12, 2013 10:36
Developer Fusion scraper: ruby UK
#!/usr/bin/ruby
require 'nokogiri'
require 'open-uri'
require 'debugger'
require 'cgi'
url = "http://www.developerfusion.com/t/ruby/jobs/"
puts url
doc = Nokogiri::HTML(open(url))
# debugger
App.accordion('.accordion','.item');
App.accordion = function(container,item){
var item_selector = container+' '+item;
$(item_selector+' .header').css('cursor','pointer');
$(item_selector+' .header').on('click',function(){
$(this).closest(item).find('.body').slideToggle();
});
};