Skip to content

Instantly share code, notes, and snippets.

View jakerr's full-sized avatar
🐦
⚙️

Jake Kerr jakerr

🐦
⚙️
View GitHub Profile
@jakerr
jakerr / gist:630521
Created October 17, 2010 03:51
Why is @email always nil?
# I'm very new to rails but a long time programmer. Anyhow I'm quite confused.
#
# I'm trying to add Devise to my User model for login
# Everything seems to be working fine but my custom hook that generates the user's
# Profile stopped working once I added in Devise.
# The @email ivar is always nil when my after_create method 'gen_profile' is called.
# What's the right way to get the email from my User in my after_create hook.
#
# Also any other suggestions I'm happy to hear. Thanks so much for looking.
#
@jakerr
jakerr / gist:1306642
Created October 22, 2011 23:51
Trying to understand Rails lifecycle

Just trying to understand the rails lifecycle

I'm exploring RouteSet to understand how / when a controller is instantiated

I was looking at this method from RouteSet:

def controller_reference(controller_param)
  controller_name = "#{controller_param.camelize}Controller"

I'd like to set an upvalue for a lua block from the c-api.

The idea is that I will load a lua file via c, and set an upvalue so the lua block that's executed knows it was loaded from the c-layer. Any subsequent loads that that block makes, should not see that same upvalue, so that code knows it was loaded indirectly from another lua script.

ltime = MOAISim.getElapsedTime()
lframe = MOAISim.getElapsedFrames()
function fps()
timer = MOAITimer.new()
timer:setSpan(5)
repeat
MOAIThread.blockOnAction(timer:start())
t = MOAISim.getElapsedTime()
f = MOAISim.getElapsedFrames()
package main
/**
* Exhibits a bug in fsnotify where removing with "rm -r" a watched dir which includes a watched file
* causes an error. Rather than delete events for each item and the containing folder.
*
* Steps to repro:
* 1.) Watch a directory
* 2.) Watch a file in the directory
* 3.) Rm -rf the directory
fn main() {
let mut orig = @1;
let mut borrow = &*orig;
io::println(fmt!("before mutate, orig: %? borrow: %?", orig, borrow));
orig = @2;
borrow = &3; // rustc gives error here, but hangs and takes 100% cpu and eventually takes 100% of memory
// error: illegal borrow: borrowed value does not live long enough
io::println(fmt!("after mutate, orig: %? borrow: %?", orig, borrow));
}
@jakerr
jakerr / try_subl.sh
Last active December 19, 2015 22:28
Retry the subl command when it fails to open the requested file.
#!/bin/bash
#
# Review this script before use and use at your own risk.
#
try_subl() {
echo "" > $temp_log
# Start recording system log.
# Start tail with 0 lines, and follow mode so we just
# get lines that occur while we try to subl.
struct PositionData {
x: int,
y: int
}
trait Position {
fn position(&self) -> PositionData;
}
trait Color {
@jakerr
jakerr / rustup.sh.diff
Last active August 29, 2015 14:07
rustup diff
diff --git a/rustup.sh b/rustup.sh
index 62a2b35..9350e55 100755
--- a/rustup.sh
+++ b/rustup.sh
@@ -231,6 +231,42 @@ validate_opt () {
probe_need CFG_CURL curl
+version() {
+ local bin_dir=$1
@jakerr
jakerr / index_mut_warnings.rs
Created November 8, 2014 11:16
Made a simple mistake and wished rustc had warned me. Here's a reproduction.
use std::collections::hash_map::HashMap;
#[deriving(Show)]
struct Adder(uint);
impl Adder {
fn add(&mut self, i: uint) {
match self {
&Adder(ref mut a) => { *a += i; }
}