Skip to content

Instantly share code, notes, and snippets.

View rodnaph's full-sized avatar
🈲
On vacation

Rhodri Pugh rodnaph

🈲
On vacation
View GitHub Profile
@rodnaph
rodnaph / hostname.yml
Created May 14, 2015 11:14
Get local hostname in Ansible
- local_action: command hostname
register: hostname
- debug: msg=hostname.stdout
<?php
namespace MyApp\MyBundle\Listener;
use JMS\DiExtraBundle\Annotation as DI;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpKernel\HttpKernelInterface;
/**
* @DI\Service()
@rodnaph
rodnaph / Vagrantfile
Created May 13, 2014 14:07
Vagrant and NFS, UDP off.
config.vm.synced_folder ".", "/path/in/vm", type: "nfs", nfs_udp: false
=============================================================================================================================================================================
Package Arch Version Repository Size
=============================================================================================================================================================================
Installing:
maven2 noarch 2.0.8-39.jpp6 jpackage-generic-free 5.7 M
Installing for dependencies:
ant noarch 1.8.2-5.jpp6 jpackage-generic-free 1.9 M
antlr noarch 2.7.7-13.jpp6 jp
@rodnaph
rodnaph / said
Last active December 27, 2015 15:59
Making sed work as I expect on OSX
#!/bin/sh
#
# Drop in ~/bin/said and chmod 755
#
# Usage:
#
# ./said 's/foo/bar/g' some/folder/*
#
find $2 -type f -exec sed -i '' $1 {} +
@rodnaph
rodnaph / core.async-lazy-sequence
Last active December 27, 2015 00:29 — forked from gerritjvv/core.async-lazy-sequence
Not tested, but can use first, and need recur to not consume stack?
(use 'clojure.core.async)
;this is the function you want to use
(defn lazy-channels [chs]
(lazy-seq
(cons (first (alts!! chs))
(recur chs))))
@rodnaph
rodnaph / lcss.clj
Last active December 22, 2015 17:59 — forked from owainlewis/lcss.clj
(ns sexp-css.core)
(defn- wrap [forms] (str "{" forms "}"))
(defn map-to-form [m] (let [outer-forms (reduce (fn [out-vec [k v]] (conj out-vec (str (name k) " : " v))) [] m) inner-forms (->> outer-forms (interpose ";") (apply str))] (wrap inner-forms)))
(defmacro defrule [selector & forms] `(str ~selector (apply map-to-form (vector ~@forms))))
(defn px [n] (when (number? n) (str n "px")))
(defn mixin [rule & forms] (merge rule (into {} forms)))
(def my-mixin
{:height "20px"
:width "100px"})
@rodnaph
rodnaph / gist:5694439
Last active December 18, 2015 00:09
Datomic attribute schema fn with sane defaults.
(ns foo.schema
(:require [datomic.api :refer [tempid]]))
;; Datomic schema is wordy, so apply some sane defaults and allow overriding where needed.
(defn- attribute [ident & options]
(let [defaults {:db/id (tempid :db.part/db)
:db/ident ident
:db/valueType :db.type/string
:db/cardinality :db.cardinality/one
@rodnaph
rodnaph / clojurescript
Last active December 16, 2015 13:38 — forked from jhickner/clojurescript
(defn debounce
([f] (debounce f 1000))
([f timeout]
(let [id (atom nil)]
(fn [evt]
(if (not (nil? @id))
(js/clearTimeout @id))
(reset! id (js/setTimeout
(partial f evt)
timeout))))))
@rodnaph
rodnaph / gist:5188923
Last active December 15, 2015 02:39
Get reference to any PHP function
<?php
function f($name)
{
return function() use ($name) {
return call_user_func_array($name, func_get_args());
};
}