Skip to content

Instantly share code, notes, and snippets.

Avatar

Nic Haynes nicinabox

View GitHub Profile
View gist:790299
$('form').submit(function() {
// get all the inputs into an array.
var $inputs = $('#form :input');
// get an associative array of just the values.
var values = {};
$inputs.each(function() {
values[this.name] = $(this).val();
if ($(this).val() == "") {
alert("You haven't filled out all the fields");
View gist:869865
users = []
xml.search('//dc:creator').each do |user|
unless users.include?(user)
users << user.inner_text
end
end
View gist:955514
# Rakefile
require File.dirname(__FILE__) + '/config/boot.rb'
require 'thor'
require 'padrino-core/cli/rake'
PadrinoTasks.init
View migration.rb
class AddAreasPortfolioEntries < ActiveRecord::Migration
def self.up
create_table "areas_portfolio_entries", :id => false do |t|
t.references :portfolio_entry
t.references :area
end
add_index :areas_portfolio_entries, :portfolio_entry_id
add_index :areas_portfolio_entries, :area_id
end
View template.html.erb
<!DOCTYPE html>
<html>
<head>
<title><%= browser_title(yield(:title)) %></title>
<meta charset='<%= ::Refinery::Application.config.encoding %>' />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<%= raw "<meta name=\"description\" content=\"#{@meta.meta_description}\" />" if @meta.meta_description.present? -%>
<%= raw "<meta name=\"keywords\" content=\"#{@meta.meta_keywords}\">" if @meta.meta_keywords.present? -%>
View deploy.sh
# $ deploy dev // Deploys to staging
# $ deploy // Deploys to production
function deploy() {
if [[ $@ != "" ]]; then
git push staging $@:master
else
git push production
fi
}
View gist:1123012
-(id)initWithName:(NSString *)n description:(NSString *)d url:(NSString *)u;
View application.html.erb
<!DOCTYPE html>
<html>
<head>
<title><%= browser_title(yield(:title)) %></title>
<% unless Rails.env == "production" %>
<meta name="robots" content="noindex" />
<% end %>
<meta charset='<%= ::Refinery::Application.config.encoding %>' />
View notify.rb
#!/usr/bin/env ruby
# Created by _zsh for r/trees
require 'rubygems'
require 'hpricot'
require 'open-uri'
require 'growl'
View canonical_redirect.rb
class CanonicalRedirect
def initialize(app)
@app = app
end
def call(env)
request = Rack::Request.new(env)
if request.host =~ /^example.com/
[301, {"Location" => request.url.sub("//", "//www.")}, self]