Skip to content

Instantly share code, notes, and snippets.

@namelessjon
namelessjon / folder.rb
Created February 19, 2012 11:02
Gist showing nested/self-referential model
class Folder
include DataMapper::Resource
has n, :subfolders, 'Folder'
has n, :messages
belongs_to :parent, :model => 'Folder', :required => false
belongs_to :owner, :model => 'User', :key => true
property :id, String, :key => true
property :name, String
@namelessjon
namelessjon / config.ru
Created June 24, 2011 20:35
Building a rack map via sinatra app inheritance.
require 'fedora'
Fedora.map.each do |route, app|
map(route) { run app }
end
@namelessjon
namelessjon / user.rb
Created June 21, 2011 22:14
Example user with a BCrypt password
require 'bcrypt'
class User
include DataMapper::Resource
attr_accessor :password, :password_confirmation
timestamps :at
property :id, Serial
@namelessjon
namelessjon / aurdiff.sh
Created March 1, 2011 10:20
script to diff local PKGBUILD with AUR pkgbuild
#!/bin/bash
# Source: https://bbs.archlinux.org/viewtopic.php?pid=853603#p853603
# Author: falconindy
DIFF=${DIFF:-diff}
if [[ ! -f PKGBUILD ]]; then
echo "error: No PKGBUILD found in working directory."
exit 1
fi >&2
@namelessjon
namelessjon / gist:799333
Created January 27, 2011 21:36
Example showing the use of the bcrypt password api
class User
def self.authenticate(email, password)
user = find_by_email(email)
if user && BCrypt::Password.new(user.password_hash) == password
user
else
nil
end
end
@namelessjon
namelessjon / gist:667660
Created November 8, 2010 12:42
Code to recursively clean a params hash.
# Copyright (c) 2010,2011 Jonathan Stott
#
# Permission is hereby granted, free of charge, to any person ob-
# taining a copy of this software and associated documentation
# files (the "Software"), to deal in the Software without restric-
# tion, including without limitation the rights to use, copy, modi-
# fy, merge, publish, distribute, sublicense, and/or sell copies of
# the Software, and to permit persons to whom the Software is fur-
# nished to do so, subject to the following conditions:
#
@namelessjon
namelessjon / gist:467349
Created July 7, 2010 21:57
basic hit counter in redis
#!/usr/bin/ruby
# Copyright (c) 2010,2011 Jonathan Stott
#
# Permission is hereby granted, free of charge, to any person ob-
# taining a copy of this software and associated documentation
# files (the "Software"), to deal in the Software without restric-
# tion, including without limitation the rights to use, copy, modi-
# fy, merge, publish, distribute, sublicense, and/or sell copies of
# the Software, and to permit persons to whom the Software is fur-
# nished to do so, subject to the following conditions:
@namelessjon
namelessjon / unicorn.config.dev.rb
Created June 8, 2010 18:00
Simple-ish reloading of the important parts of an app on changes
# Sample configuration file for Unicorn (not Rack)
worker_processes 1
# listen on the sinatra port
listen 4567
# feel free to point this anywhere accessible on the filesystem
pid "#{ENV['XDG_CACHE_HOME']}/unicorn.pid"
stdout_path "#{ENV['XDG_CACHE_HOME']}/unicorn.log"
@namelessjon
namelessjon / own-mustache.rb
Created June 8, 2010 14:27
Simple implentation for embedding mustache template in a script
#!/usr/bin/ruby
# Copyright (c) 2010 Jonathan Stott, unless otherwise noted
#
# Permission is hereby granted, free of charge, to any person ob-
# taining a copy of this software and associated documentation
# files (the "Software"), to deal in the Software without restric-
# tion, including without limitation the rights to use, copy, modi-
# fy, merge, publish, distribute, sublicense, and/or sell copies of
# the Software, and to permit persons to whom the Software is fur-
# nished to do so, subject to the following conditions:
@namelessjon
namelessjon / dm-more-rewrite.rb
Created April 10, 2010 10:30
Split and re-write dm-more history
#!/usr/bin/ruby
# Jonathan D. Stott <jonathan.stott@gmail.com>
require 'fileutils'
require 'octopi'
include Octopi
def sh(command)
system command || abort(command)
end