Skip to content

Instantly share code, notes, and snippets.

BIG_HASH_OF_OFTEN_UNCHANGING_VALUES = { ... }
BIG_HASH_OF_A_FEW_CHANGED_VALUES = { ... }
# Solve for x:
BIG_HASH_OF_OFTEN_UNCHANGING_VALUES.merge(x) == BIG_HASH_OF_A_FEW_CHANGED_VALUES + y
# where y is a set of k => v pairs that are in UNCHANGING but not in A_FEW_CHANGED
x = {}
BIG_HASH_OF_A_FEW_CHANGED_VALUES.each do |k, v|
x[k] = v unless v == BIG_HASH_OF_OFTEN_UNCHANGING_VALUES[k]
# Basic Setup:
class User
has_one :widget, :dependent => :destroy
end
class Widget
belongs_to :user
end
@benmanns
benmanns / redirect.html
Created April 19, 2011 14:42
Redirect demo for Mechanize meta refresh issue.
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>Redirect</title>
<meta name="author" content="Benjamin Manns" />
<meta http-equiv="refresh" content="10;url=http://mechanize.rubyforge.org/mechanize/" />
</head>
<body>
<div>
require 'benchmark'
def benchmark(setting, &block)
data = (1..10_000_000).map { block.call }
Benchmark.bm(15) do |x|
x.report("compact #{setting}") do
data.dup.each do |d|
[d[0],d[1]].compact.min
end
@benmanns
benmanns / README.markdown
Created November 17, 2010 22:33
This is a library for polling Liberty's ASIST portal (hence the name).

Asistant

To get this set up you have to run custom versions of the mechanize and twiliolib gems. Unfortunately, some SSL errors and issues with Liberty's login redirect sequence forced me to hack the libraries. Hopefully I can get something "official" looking to get it pulled into the main repository, but for now, install it from my repositories.

Generic Ruby Setup

sudo apt-get install ruby

Generic RubyGems Setup

<?php
class GroupsController extends AppController {
var $name = 'Groups';
var $paginate = array(
'fields' => array(
'Group.id',
'Group.icon',
'Group.name',
'GroupCategory.name',
'Group.location',
#!/bin/sh
# NOTE: UGLY!
for i in {0..44} # I think I could have done this with filter-branch, but I'm not sure how to use it.
do
git rebase --continue
lines=$(cat OgreIsland/Sockets/Socket.cs | wc -l)
lines=$(expr $lines - 18)
function add() {
if (!empty($this->data)) {
$user = $this->User->find('first', array('conditions' => array('User.activation_token' => $this->data['User']['activation_token'])));
if($user) {
$this->data['User']['activated'] = '-!NOW()';
$this->data['User']['activation_token'] = '-!NULL';
$this->User->id = $user['User']['id'];
}
$this->User->save($this->data);
}
module ApplicationHelper
def spell_text(text)
words = text.split('').map do |letter|
content_tag 'Say' do
letter.sub('.', 'dot').sub('-', 'dash')
end
end
end
end
array(
'name' => array(
'notempty' => array(
'rule' => array('notempty'),
'allowEmpty' => false,
'required' => true,
),
'isUnique' => array(
'rule' => array('isUnique'),
'message' => 'That group name has already been registered.',