Skip to content

Instantly share code, notes, and snippets.

@dmac
dmac / macro-lambda.rkt
Created September 16, 2011 19:11
How to define a macro with a lambda, then access that lambda's arguments?
#lang racket
(define-syntax-rule (foo form ...)
((lambda (bar) form ...) "ARG"))
(foo "Hello") ; => returns "Hello"
(foo bar) ; => expand: unbound identifier in module in: bar
@dmac
dmac / gist:6915567
Last active December 25, 2015 04:09
ansible conditionals
# I want to run bartask only if a line output from footask starts with a period.
# I'm not sure what is valid to use for "???" below.
# Things that don't work are: is, =, ==, equals, sameas, find.
- name: footask
command: ...
register: manifest
- name: bartask
debug: msg="bartask ran"
@dmac
dmac / example.sh
Last active December 25, 2015 07:19
conditionally including tasks with "when" fields
$ ansible-playbook playbook.yml
PLAY [playbook] *************************************************************
GATHERING FACTS ***************************************************************
ok: [hosts]
TASK: [register a var] ********************************************************
skipping: [hosts]
TASK: [print a var] ***********************************************************
@dmac
dmac / gist:6996258
Created October 15, 2013 18:25
ansible dict iteration
---
- hosts: localhost
vars:
- foo:
a: 1
b: 2
c: 3
tasks:
- debug: msg="{{ item }} is {{ foo[item] }}"
with_items: foo|list
@dmac
dmac / etc hosts
Created October 17, 2013 13:17
ansible host module: aliases and changed status
127.0.0.1 localhost
@dmac
dmac / main1.rs
Last active January 3, 2016 12:39
borrowed value lifetimes
fn main() {
println!("{:?}", format!("{}", 1).as_bytes());
}
/*
main.rs:2:22: 2:39 error: borrowed value does not live long enough
main.rs:2 println!("{:?}", format!("{}", 1).as_bytes());
^~~~~~~~~~~~~~~~~
main.rs:2:14: 2:20 note: reference must be valid for the block at 2:13...
main.rs:2 println!("{:?}", format!("{}", 1).as_bytes());
@dmac
dmac / main.rs
Last active January 3, 2016 23:08
rust collect
use std::hashmap::HashMap;
fn main() {
let v = [("a", 1), ("b", 2), ("c", 3)];
let m: HashMap<~str, int> = v.iter().map(|&(s, n)| (s.to_owned(), n)).collect();
let keys = [~"a", ~"b", ~"c"];
for k in keys.iter() {
println!("{:?}: {:?}", k, m.get(k));
}
}
@dmac
dmac / test.yml
Last active August 29, 2015 14:09
ansible lineinfile
- name: test playbook
hosts: localhost
tasks:
- name: test lineinfile
local_action: lineinfile dest="{{ playbook_dir }}"/test.txt state=present line=foo create=yes
# failed: [127.0.0.1 -> 127.0.0.1] => {"failed": true}
# msg: missing required arguments: regexp
@dmac
dmac / inventory
Created March 20, 2015 00:32
ansible group vars
[group1]
localhost
[group1:vars]
n = 1
[group2]
localhost
[group2:vars]
int main(void) {
int x = 1;
x = x + 0.1;
}