Skip to content

Instantly share code, notes, and snippets.

View adamrobbie's full-sized avatar

Adam Robbie adamrobbie

View GitHub Profile
@adamrobbie
adamrobbie / getParametersByName.js
Created June 28, 2012 16:04
javascript, get URL paramters
function getParameterByName(name)
{
name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
var regexS = "[\\?&]" + name + "=([^&#]*)";
var regex = new RegExp(regexS);
var results = regex.exec(window.location.search);
if(results == null)
return "";
else
return decodeURIComponent(results[1].replace(/\+/g, " "));
@adamrobbie
adamrobbie / loadAsynchronousJS.js
Created June 28, 2012 17:24
js to load js without blocking .onload() via Stoyan
(function(url){ var iframe = document.createElement('iframe'); (iframe.frameElement || iframe).style.cssText = "width: 0; height: 0; border: 0"; var where = document.getElementsByTagName('script'); where = where[where.length - 1]; where.parentNode.insertBefore(iframe, where); var doc = iframe.contentWindow.document; doc.open().write('<body onload="'+ 'var js = document.createElement(\'script\');'+ 'js.src = \''+ url +'\';'+ 'document.body.appendChild(js);">'); doc.close(); })('http://www.jspatterns.com/files/meebo/asyncjs1.php');
@adamrobbie
adamrobbie / htmlentity.txt
Created June 29, 2012 17:15
html entity reference
Name Character Entity
Copyright © &copy;
Registered ® &reg;
Trademark ™ &trade;
Curly Open Double Quote “ &ldquo;
Curly Closed Double Quote ” &rdquo;
Curly Open Single Quote ‘ &lsquo;
Curly Closed Single Quote ’ &rsquo;
Big Bullet/Dot • &bull;
Small Bullet/Dot · &middot;
@adamrobbie
adamrobbie / readmeTutorial.txt
Created July 11, 2012 16:23
How to write a good README
Here's what I think it should include:
name of the projects and all sub-modules and libraries (sometimes they are named different and very confusing to new users)
descriptions of all the project, and all sub-modules and libraries
5-line code snippet on how its used (if it's a library)
copyright and licensing information (or "Read LICENSE")
instruction to grab the documentation
instructions to install, configure, and to run the programs
instruction to grab the latest code and detailed instructions to build it (or quick overview and "Read INSTALL")
list of authors or "Read AUTHORS"
@adamrobbie
adamrobbie / remove_non_alphas.rb
Created July 26, 2012 15:40
Reg ex expression to parse text removing all non-alphabet characters
message = message.gsub(/[^0-9a-z]/i, '')
@adamrobbie
adamrobbie / gist:3194878
Created July 28, 2012 21:31 — forked from iamjpg/gist:3194394
The Iron by Henry Rollins
This article originally appeared in Details Magazine some time around 1994 or 1995, I believe. This is a great essay by Henry Rollins on the benefits and lessons of lifting weights.
=================================================
I believe that the definition of definition is reinvention. To not be like your parents. To not be like your friends. To be yourself.
Completely.
When I was young I had no sense of myself. All I was, was a product of all the fear and humiliation I suffered. Fear of my parents. The humiliation of teachers calling me "garbage can" and telling me I'd be mowing lawns for a living. And the very real terror of my fellow students. I was threatened and beaten up for the color of my skin and my size. I was skinny and clumsy, and when others would tease me I didn't run home crying, wondering why.
@adamrobbie
adamrobbie / gitpush.txt
Created July 31, 2012 15:31
Fix gitup push ref permission
ssh me@myserver
cd repository.git
sudo chmod -R g+ws *
sudo chgrp -R mygroup *
git repo-config core.sharedRepository true
@adamrobbie
adamrobbie / async_helper.rb
Created August 3, 2012 14:48
Rails Helper to call javascript asynchronous
module AsyncHelper
def javascript_async(*args)
content_tag :script, type: "text/javascript" do
"(function() {
var script = document.createElement('script');
script.type = 'text/javascript';
script.async = true;
script.src = '#{j javascript_path(*args)}';
var other = document.getElementsByTagName('script')[0];
@adamrobbie
adamrobbie / handle_orphaned.task
Created August 29, 2012 13:14
Rake task to handle orphaned records
namespace :db do
desc "Handle orphans"
task :handle_orphans => :environment do
Dir[Rails.root + "app/models/**/*.rb"].each do |path|
require path
end
ActiveRecord::Base.send(:descendants).each do |model|
model.reflections.each do |association_name, reflection|
if reflection.macro == :belongs_to
model.all.each do |model_instance|
@adamrobbie
adamrobbie / controller.rb
Created August 30, 2012 13:42 — forked from joakimk/controller.rb
A way to lazy load partials in Rails 3
class Controller
include LazyLoad
def show
@model = Model.find(...)
respond_to do |format|
format.html do
@html_specific_data = Model.find(...)
end