Skip to content

Instantly share code, notes, and snippets.

View Jamedjo's full-sized avatar

James EdJo Jamedjo

View GitHub Profile
@Jamedjo
Jamedjo / strikingly_email_cookie.html
Last active August 29, 2015 14:17
Store Strikingly email in a cookie
@Jamedjo
Jamedjo / sprites.rake
Created February 1, 2015 22:29
Resize images and move from ./originals to ./
namespace :sprites do
originals = Rake::FileList.new('app/assets/images/**/originals/*.png')
resized = originals.pathmap("%{/originals$,/}d%f")
task resize: resized
end
from_originals = ->(tn) {
tn.pathmap("%d/originals/%f")
}
@Jamedjo
Jamedjo / undo.hs
Created November 21, 2014 19:57
Standalone version of lambdabot's undo function.
-- Copyright (c) 2006 Spencer Janssen
-- GPL version 2 or later (see http://www.gnu.org/copyleft/gpl.html)
{-# LANGUAGE Rank2Types #-}
module Main where
import Control.Monad
import Data.Generics
# http://www.codewars.com/kata/batchitemprocessor/ruby
require './batchitemprocessor'
class Test
# This class mimics the one provided in the kata
def self.assert_equals(actual, expected, message="")
if actual!=expected
puts "\nTest '#{message}' failed.\nExpected #{expected}\nGot #{actual}"
else
puts "."
@Jamedjo
Jamedjo / sign_in_helpers.rb
Created January 31, 2014 00:47
Capybara sign in/up helpers for use with Cucumber. Uses FactoryGirl to get sign up attributes, and to create a user for signing in.
module SignInHelpers
def sign_up_as(user_type, form_params={})
attributes = FactoryGirl.attributes_for(user_type).merge(form_params)
destory_user(attributes[:email])
visit '/users/sign_up'
within("#new_user") do
fill_in "Name", :with => attributes[:name]
fill_in "Email", :with => attributes[:email]
fill_in "Password", :with => attributes[:password]
class VntReader
def initialize(file)
@file=file
end
def body
@file.each_line.select{|l|l.match /\ABODY/}.first.chomp
end
def content

Like content_for but takes a default output from a block if content_for? hasn't been set.

= content_default(:sidebar) do
  = render 'sidebar'
@Jamedjo
Jamedjo / angular_linkto.md
Last active December 31, 2015 20:49
Angularjs compatible link_to. Adds target="_self" to all links created with link_to, so $location doesn't hijack the link. Useful if an external gem/engine is using link_to.

Angularjs link_to

Angular compatible link_to. Turns

<%= link_to "Sign up", "/users/sign_up" %>

into

Sign up

@Jamedjo
Jamedjo / Subdomain.md
Last active December 28, 2015 01:09
Super basic rails subdomain library.

Simple Subdomain

Super simple library for using subdomains in your rails routes.

Lets you do

subdomain('online') do
  root :to => 'online#index'
end

in your routes.rb.

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();
});
};