Skip to content

Instantly share code, notes, and snippets.

View mbbx6spp's full-sized avatar
🎯
Focusing

Susan Potter mbbx6spp

🎯
Focusing
View GitHub Profile
@mbbx6spp
mbbx6spp / capistrano_git_tasks.rb
Created July 24, 2009 19:16
Git (submodule) Capistrano tasks
# 2009 Copyright Susan Potter <me at susanpotter dot net>
# You can read her software development rants at: http://geek.susanpotter.net
# Released under CreativeCommons-attribution-noncommercial-sharealike license:
# http://creativecommons.org/licenses/by-nc-sa/1.0/
namespace :git do
namespace :submodule do
desc "Initializes submodules"
task :init, :roles => :app do
invoke_command "cd #{current_path} && git submodule init", :via => run_method
end
@mbbx6spp
mbbx6spp / capistrano-memcached.rb
Created July 24, 2009 19:53
Memcached Capistrano tasks
# 2007 Copyright Susan Potter <me at susanpotter dot net>
# You can read her software development rants at: http://geek.susanpotter.net
# Released under CreativeCommons-attribution-noncommercial-sharealike license:
# http://creativecommons.org/licenses/by-nc-sa/1.0/
namespace :memcached do
desc "Restart the Memcache daemon"
task :restart, :roles => :app do
deploy.memcached.stop
deploy.memcached.start
end
# template for Spec Matcher
Spec::Matchers.define :be_an_alien do |planet|
match do |creature|
creature.alien_of?(planet)
end
failure_message_for_should do |creature|
"expected that #{creature} would be an alien of #{planet}"
end
@mbbx6spp
mbbx6spp / javascript.rake
Created January 7, 2010 16:26
JSLint configuration for a Rails project using jQuery. Can use with other frameworks if you remove "+define jQuery" and replace with your library's global name.
namespace :js do
desc 'Run Javascript Lint on engine-specific Javascript files.'
task :lint do
config_file = ENV["JSL_CFG"] || File.join('spec', 'javascripts', 'jsl.conf')
if File.exist?(config_file)
output = %x[jsl -conf #{config_file}]
puts output
else
puts "Warning: No JSLint configuration file specified nor default location (spec/javascripts/jsl.conf) exists."
end
/* 2009-2010 (c) Copyright Susan Potter. http://geek.susanpotter.net */
/* Released under MIT License. */
/* Example using node.js */
(function () {
var sys = require('sys');
var http = require('http');
const PORT = 8080;
http.createServer(function (req, res) {
@mbbx6spp
mbbx6spp / Neo4J Gay Marriage Example
Created April 3, 2010 16:36
Code sample from 'Why proponents of marriage equality should love graph databases, Part 2' http://bit.ly/dccCPj
// Creative Commons Attribution-Share Alike 3.0 United States License
// http://creativecommons.org/licenses/by-sa/3.0/us/
// From blog post: http://bit.ly/dccCPj
package net.susanpotter.inclusivemarriage;
import java.text.SimpleDateFormat;
import java.text.ParseException;
import java.util.Date;
import org.neo4j.graphdb.*;
@mbbx6spp
mbbx6spp / controller_snippet.rb
Created April 10, 2010 15:47
UJS translation of ugly RJS problem posted to Devchix that I responded to on 2010-04-10.
# PUT /users/1
def update
@user = @session_user
respond_to do |format|
if @user.update_attributes(params[:user])
format.js do
render :json => {:status => 'success', :html => (render_to_string(:partial => 'display_avatar', :locals => { :user => @user })) }
end
format.html do
flash[:notice] = 'The resource was updated'
@mbbx6spp
mbbx6spp / page.coffee
Created April 13, 2010 21:59
jQuery API usage example in CoffeeScript translated to Javascript.
# Creative Commons Attribution-Share Alike 3.0 United States License
# http://creativecommons.org/licenses/by-sa/3.0/us/
# By Susan Potter <http://geek.susanpotter.net>
(($) ->
editSubmitHandler: (evt) ->
form: $(this)
data: form.serialize()
url: form.attr('action')
$.getJSON(url, data, (data, resp) ->
$('#notice').html(data['html'])
@mbbx6spp
mbbx6spp / simple_math.coffee
Created April 13, 2010 22:30
Simple math CoffeeScript example translated to Javascript.
# Creative Commons Attribution-Share Alike 3.0 United States License
# http://creativecommons.org/licenses/by-sa/3.0/us/
# By Susan Potter <http://geek.susanpotter.net>
(() ->
window: this
window.SimpleMath: {
square: (x) ->
x*x
cube: (x) ->
x*x*x
@mbbx6spp
mbbx6spp / balance_sheet.coffee
Created April 13, 2010 23:00
Balance sheet object model example to demonstrate CoffeeScript and translated Javascript.
# Creative Commons Attribution-Share Alike 3.0 United States License
# http://creativecommons.org/licenses/by-sa/3.0/us/
# By Susan Potter <http://geek.susanpotter.net>
class BalanceSheet
constructor: (companyName, date) ->
@companyName: companyName
@date: date
@assets: []
@liabilities: []
entries: ->