Skip to content

Instantly share code, notes, and snippets.

View johno's full-sized avatar
🖤
Computering

John Otander johno

🖤
Computering
View GitHub Profile
@johno
johno / linkz.rb
Last active December 17, 2015 16:38
Trigger partial swap upon button click.
<%= link_to 'Notify Yourself',
'#',
onclick: "uceem.fade('#notification_prompt', '#{ j render(partial: 'notify_yourself_form').html_safe }');",
class: 'btn btn-primary btn-large' %>
<%= link_to 'Notify Another User',
'#',
onclick: "uceem.fade('#notification_prompt', '#{ j render(partial: 'notify_another_user_form').html_safe }');",
class: 'btn btn-primary btn-large' %>
@johno
johno / array_data_struct.rb
Last active December 17, 2015 17:09
Test the performance differences between an array and hash for key lookup with the Swot gem. Run with `$ ruby performance_test.rb <number_of_tests || default: 100>`
module ArrayDataStruct
ACADEMIC_TLDS = [
'ac.ae',
'ac.at',
'ac.bd',
'ac.be',
'ac.cr',
'ac.cy',
'ac.fj',
import re; import sys
from collections import defaultdict
try:
file = open(sys.argv[1])
except:
print "Usage: python wf.py <path_to_file/filename>"
word_freq = defaultdict(int)
for line in file:
@johno
johno / feedzirra.rb
Created June 26, 2013 20:54
Using feedzirra
require 'feedzirra'
feed = Feedzirra::Feed.fetch_and_parse('http://feeds.feedburner.com/TechCrunch/')
puts feed.title
puts feed.url
puts feed.feed_url
puts feed.etag
puts feed.last_modified
@johno
johno / example.rb
Created July 8, 2013 21:32
Clean up some ternary statements.
device["signal_strength"] == nil ? '0' : device["signal_strength"]
# You can also can use the following:
device['signal_strength'] || 0
@johno
johno / duck_ie.js
Last active December 20, 2015 12:59
Duck IE
// From http://stackoverflow.com/questions/3680429/click-through-a-div-to-underlying-elements/4839672#4839672
$('.duck_ie').click(function(e) {
var left = $(window).scrollLeft();
var top = $(window).scrollTop();
//hide the overlay for now so the document can find the underlying elements
$(this).css('display','none');
//use the current scroll position to deduct from the click position
@johno
johno / sexify_devise.js.coffee
Last active December 21, 2015 02:49
Grab devise form content, like an email, and add it as a parameter to populate the next form. This can be rather helpful when a user realizes they forgot their email, now they won't have to retype it.
$ ->
devise.grabUserEmailToSendAsParam()
devise =
grabUserEmailToSendAsParam: ->
$('.grab-email').on('click', ->
if $('#user_email').val().length
$(this).attr('href', $(this).attr('href') + "?email=#{ $('#user_email').val() }") )
john-bigmac~/my_gems/cradlepoint>master:% gem push cradlepoint-0.2.1.gem
Pushing gem to https://rubygems.org...
<html>
<head><title>500 Internal Server Error</title></head>
<body bgcolor="white">
<center><h1>500 Internal Server Error</h1></center>
<hr><center>nginx</center>
</body>
</html>
@johno
johno / get_rails_going.sh
Last active December 22, 2015 20:59
Get rails up and running.
#!bin/sh
ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go)"
\curl -L https://get.rvm.io | bash -s stable
brew install openssl
rvm install 2.0.0
rvm use 2.0.0
gem install bundler
@johno
johno / html.html
Created October 17, 2013 22:16
Unobtrusive masonry for http://masonry.desandro.com/.
<div class="masonry" data-masonry-element="widget" data-masonry-gutter=20>
<!-- ... -->
</div>