Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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 / 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 / zxcvbn.html
Created April 11, 2012 15:26
hacky little js/html to figure out password entropy with zxcvbn and show password anatomy
<html>
<head>
<title>zxcvbn</title>
</head>
<body>
<h1>pass</h1>
<input />
<dl>
<dt>Entropy</dt>
<dd id='e'>0</dd>
@namelessjon
namelessjon / markdown2html.rb
Created May 16, 2012 10:19
My redcarpet-using script to convert my markdown notes into a html file. Is customised a little to cope with textile sections, making figures, and some basic html entity replacement.
#!/usr/bin/ruby
# Now with a hacky outline too, generated after: http://blog.steveklabnik.com/posts/2011-12-21-redcarpet-is-awesome
filename = ARGV.first
filename = File.basename(filename) if filename
require 'redcloth'
require 'redcarpet'
require 'yaml'
require 'mustache'
@namelessjon
namelessjon / friendship_example.rb
Created June 10, 2012 10:20
Example of friendships and retriving all records.
#!/usr/bin/env ruby
#
# Example of friendships and retriving all records.
require 'rubygems'
require 'dm-core'
require 'dm-migrations'
# setup the logger
DataMapper::Logger.new($stdout, :debug)
@namelessjon
namelessjon / planter.rb
Created October 19, 2012 09:27 — forked from ttscoff/planter.rb
Create directory trees from indented text input
#!/usr/bin/ruby
# ruby script to create a directory structure from indented data.
# Three ways to use it:
# - Pipe indented (tabs or 2 spaces) text to the script
# - e.g. `cat "mytemplate" | planter.rb
# - Create template.tpl files in ~/.planter and call them by their base name
# - e.g. Create a text file in ~/.planter/site.tpl
# - `planter.rb site`
# - Call planter.rb without input and it will open your $EDITOR to create the tree on the fly
# You can put %%X%% variables into templates, where X is a number that corresponds to the index
@namelessjon
namelessjon / gist:5518574
Last active December 17, 2015 00:09
Rough sketch of the internal organisation for game app. Is this kind of thing safe with respect to potentially overlapping calls of the various methods on rooms that might iterate over it while other methods add/delete from it?
class Webapp
include Reel::App
get '/' do
rooms = Actor[:rooms].list_rooms
# serialize and stuff here
end
post '/:room' do
# do some stuff