Skip to content

Instantly share code, notes, and snippets.

@bcalloway
bcalloway / environment.rb
Created March 2, 2009 18:53
ActionMailer with Gmail
#
# Add this to the bottom of environment.rb
#
require 'smtp_tls'
ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.raise_delivery_errors = true
ActionMailer::Base.smtp_settings = {
@bcalloway
bcalloway / hide-email.js
Created March 7, 2009 20:03
Hide email from spambots
<script language="JavaScript">
<!--
var name = "email";
var domain = "mydomain.com";
document.write('<a href=\"mailto:' + name + '@' + domain + '\">');
document.write(name + '@' + domain + '</a>');
//-->
</script>
@bcalloway
bcalloway / import-csv.php
Created March 7, 2009 20:07
Import a csv file into MySQL
<?php
//Define Variables
$host='localhost'; //hostname of database
$user='user'; //username of database
$pass='pass'; //password of database
$dbname='database'; //name of database
$table='table'; //name of table
$file='spreadsheet.csv'; //name of file to be imported (including extension)
@bcalloway
bcalloway / gitignore
Created April 30, 2009 15:09
.gitignore file
.DS_Store
log/*.log
tmp/**/*
db/schema.rb
!.keep
@bcalloway
bcalloway / github_sunburst_syntax_h.user.js
Created May 20, 2009 14:28
Sunburst Theme for Github - Greasemonkey Required
// ==UserScript==
// @name Github Sunburst Syntax Highlight
// @namespace
// @description Textmate-style syntax highlighting for GitHub
// @include http://github.com/*
// @include https://github.com/*
// @include http://*.github.com/*
// @include https://*.github.com/*
// ==/UserScript==
(function() {
@bcalloway
bcalloway / rails-export-csv.rb
Created July 29, 2009 22:08
Use FasterCSV to export an ActiveRecord object in Rails
### /config/environment.rb
config.gem 'fastercsv'
### /config/routes.rb
map.connect '/users/export', :controller => 'users', :action => 'export'
### /app/models/user.rb
# find all students and pass to controller export action for export to csv
def self.find_students
find_by_sql("select students.firstname, students.lastname, students.grade, students.homeroom, students.phone, students.email, students.relationship, users.firstname, users.lastname, accounts.school from students, users, accounts where students.user_id = users.id and accounts.id = users.account_id")
@bcalloway
bcalloway / sub-nav.html
Created September 17, 2009 12:39
Sub-Nav of child pages in Radiant
## In layout
<div id="subnav">
<ul>
<r:snippet name="sub-nav" />
</ul>
</div>
## In snippet named "sub-nav"
## This also adds an "active" class to the current page link
<r:if_parent>
@bcalloway
bcalloway / show_locations.rb
Created November 3, 2009 16:56
Parse XML file with Nokogiri
xml = File.read("db/getLocationsForUrl.xml")
@doc = Nokogiri::XML.parse(xml)
locations = []
locations.push("<option value=\"\">-- Select a Location --</option>")
@doc.xpath('/env:Envelope/env:Body/Array/item/return/item').each do |node|
id = node.xpath('id')
name = node.xpath('name')
locations.push("<option value=\"#{id.text}\">#{name.text}</option>")
@bcalloway
bcalloway / _results.html.haml
Created November 23, 2009 16:27
Ajax pagination
// app/views/users/_results.html.haml
%table.table
- @users.each do |user|
%tr
%td
= h user.name
%td
= link_to 'Show', user
|
@bcalloway
bcalloway / getUrlVars.js
Created January 19, 2010 16:16
jQuery script to grab params from URL
$.extend({
getUrlVars: function(){
var vars = [], hash;
var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
for(var i = 0; i < hashes.length; i++)
{
hash = hashes[i].split('=');
vars.push(hash[0]);
vars[hash[0]] = hash[1];
}