Skip to content

Instantly share code, notes, and snippets.

View jakerr's full-sized avatar
🐦
⚙️

Jake Kerr jakerr

🐦
⚙️
View GitHub Profile
extern crate proc_macro;
use proc_macro::TokenStream;
#[proc_macro_attribute]
pub fn if_mac_or_win_cfg(_attr: TokenStream, item: TokenStream) -> TokenStream {
let mut stream = "#[cfg(any(target_os = \"macosx\", target_os = \"windows\"))]".parse::<TokenStream>().unwrap();
stream.extend(item);
stream
}
@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; }
}
@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
struct PositionData {
x: int,
y: int
}
trait Position {
fn position(&self) -> PositionData;
}
trait Color {
@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.
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));
}
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
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()

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.

@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"