Skip to content

Instantly share code, notes, and snippets.

View epochwolf's full-sized avatar

Epoch Wolf epochwolf

View GitHub Profile
def create_wiki_token(user, expires)
doku_data = {
:user => user.name,
:email => user.email,
:groups => user.wiki_groups,
:expires => expires.to_i
}
doku_data = Base64.encode64(doku_data.to_json)
secret = Rails.application.config.cookie_secret
doku_digest = OpenSSL::HMAC.hexdigest(OpenSSL::Digest.const_get("SHA1").new, secret, doku_data)
# First rule of pasting code, add comments to explain logic and data structres
# when it's non-obvious in the code. (Pretty much always)
class MongoMapperDocument
# Searches for documents
#
# Structure for `criteria`
# [
# {
# "field" => "comments_count"
#! /usr/bin/ruby
# This program takes a list of users, their desires, and their possessions.
# Then it asks for a particular user and matches them with the best user
# for their desires.
class User
attr_reader :has, :wants
attr_accessor :score
def initialize (has=[], wants=[])
@score = 0
[2010-09-16 09:46:40] make
dln.c: In function ‘dln_load’:
dln.c:1463: warning: ‘NSCreateObjectFileImageFromFile’ is deprecated (declared at /usr/include/mach-o/dyld.h:145)
dln.c:1469: warning: ‘NSLinkModule’ is deprecated (declared at /usr/include/mach-o/dyld.h:161)
dln.c:1472: warning: ‘NSIsSymbolNameDefined’ is deprecated (declared at /usr/include/mach-o/dyld.h:176)
dln.c:1475: warning: ‘NSAddressOfSymbol’ is deprecated (declared at /usr/include/mach-o/dyld.h:188)
dln.c:1475: warning: ‘NSLookupAndBindSymbol’ is deprecated (declared at /usr/include/mach-o/dyld.h:179)
file.c: In function ‘lchmod_internal’:
file.c:1791: warning: cast from pointer to integer of different size
regex.c: In function ‘ruby_re_compile_pattern’:
# route
get "flag/:root_type/:root_id" => 'flags#show', :as => :flag
#linking to it
link_to "Flag this", flag_path("journal", @journal.id)
# the :as option in the route generates a method named "#{option[:as]}_path"
# this method has two ways to call it
@epochwolf
epochwolf / db.rake
Created February 8, 2011 03:23
db:genesis Drop in lib/tasks in a rails application for great justice
namespace :db do
desc "[CUSTOM] Nuke the database, run all migrates on a new database, and reseed."
task :genesis do
# McCoy: Dear Lord. You think we're intelligent enough to... suppose... what if this thing were used where data already exists?
Rake::Task['db:drop'].invoke
# Spock: It would destroy such data in favor of its new schema.
Rake::Task['db:create'].invoke
# McCoy: Its "new schema"? Do you have any idea what you're saying?
Rake::Task['db:migrate'].invoke
# Spock: I was not attempting to evaluate its moral implications, Doctor. As a matter of cosmic history, it has always been easier to destroy than to create.
@epochwolf
epochwolf / save_record.rb
Created August 2, 2011 14:11
Save Record mixing for Application Controller
module ControllerMixins::SaveRecord
def attached_events
@_attached_events ||= []
end
def save_events(&block)
save_events!(&block)
rescue ActiveRecord::RecordNotSaved
class HtmlInput < SimpleForm::Inputs::Base
def input
options = input_html_options
options[:data] ||= {}
options[:data][:widget] = 'ckeditor'
@builder.text_area attribute_name, options
end
end
accept = <%= param[:accept] || accept %>
connect = <%= param[:connect] || connect %>
cert = <%= param['cert'] || cert %>
key = <%= param['key'] || key %>
CAfile = <%= param['cafile'] || cafile %>
CRLfile = <%= param['crlfile'] || crlfile %>
@epochwolf
epochwolf / to_one_file.rb
Created October 1, 2013 04:00
A script to extract the text from a local copy of unitysaga.com into a single html file suitable for conversion to an ebook. Never underestimate the lengths to which a nerd will go to get something on their kindle.
#!/usr/bin/env ruby
# A script to extract the text from a copy of unitysaga.com into a single file.
# Copyright (C) 2013 epochwolf
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of
# this software and associated documentation files (the "Software"), to deal in
# the Software without restriction, including without limitation the rights to
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
# the Software, and to permit persons to whom the Software is furnished to do so,