Skip to content

Instantly share code, notes, and snippets.

@brookr
brookr / Google Apps Standard DNS Settings
Last active May 25, 2017 16:11
All the DNS records for a new Google Apps account, as entered in AWS:Route53
A: # If using naked domain redirects via Google
216.239.32.21
216.239.34.21
216.239.36.21
216.239.38.21
MX: # If using Google Mail
1 ASPMX.L.GOOGLE.COM.
5 ALT1.ASPMX.L.GOOGLE.COM.
5 ALT2.ASPMX.L.GOOGLE.COM.
@cgrand
cgrand / restrict-map.clj
Created May 29, 2012 10:15
Restricting nested maps to keys of interest
;; I could have used a closed dispatch (aka cond) but you may find this version more enjoyable
;; the spec format is the one provided by BG
(defprotocol Selector
(-select [s m]))
(defn select [m selectors-coll]
(reduce conj {} (map #(-select % m) selectors-coll)))
(extend-protocol Selector
@natan
natan / archive-desktop.rb
Last active October 11, 2015 05:17
Move everything on your desktop into ~/Dropbox/Documents/Desktops/<yyyy-mm-dd>/
#!/usr/bin/env ruby
require 'FileUtils'
require 'date'
def create_dir_if_necessary(path)
Dir.mkdir(path) unless File.directory?(path)
end
desktops_path = File.expand_path("~/Dropbox/Documents/Desktops")
@jeremy
jeremy / gist:4035286
Created November 7, 2012 23:15
Enumerable#associate

We've seen lots of Ruby feature requests about converting an Enumerable to a Hash: to_h, map_hash, map_to, each_with_hash, etc. Let's look at one common, simple case of this.

Building a key/value mapping from a collection of keys is awkward. We commonly see Hash[*collection.map { |element| [element, calculate(element)] }] or collection.each_with_object({}) { |element, hash| hash[element] = calculate(element) }. Both are verbose. They require boilerplate code that's not relevant to the programmer's intent: to associate an enumerable of keys with calculated values.

Ruby has the idea of an association already: a key and value paired together. It's used by Array#assoc to look up a value from a list of pairs and by Hash#assoc to return a key/value pair. Building up a mapping of key/value pairs is associating keys with values.

So! Consider Enumerable#associate which builds a mapping by associating keys with values:

# Associate filenames with URLs. Before:
@ept
ept / gist:4475995
Last active November 4, 2022 08:38
Syntax highlighting code for PowerPoint (Mac OS)

How to add syntax-highlighted code to PowerPoint slides (Mac OS)

  1. pygmentize -f rtf FILE | pbcopy
  2. Paste into TextEdit (in rich text mode: Format → Make Rich Text before pasting), and copy to clipboard again.
  3. In PowerPoint, Edit → Paste Special… → Styled Text.

(Pasting RTF directly into PowerPoint doesn't work correctly, at least with PowerPoint 2008 — it extends colour spans longer than it should, and sometimes removes line breaks. Going via TextEdit seems to solve the problem.)

(def cds (collection))
;; interact with database
(go
(>! (:in cds)
{:op :create
:val {:title "Soft Machine Vol. 1"
:artist "Soft Machine"
:year 1969}})
(defn take-until
([pred-sentinel in] (take-until pred-sentinel in (chan)))
([pred-sentinel in out]
(go (loop []
(if-let [v (<! in)]
(do
(>! out v)
(if-not (pred-sentinel v)
(recur)
(close! out)))
@hsjunnesson
hsjunnesson / log
Created September 5, 2013 21:28
Update: I've made a more thorough example of embedding Clojure logic in an iPhone app. Toes, a tic-tac-toe game in clojure on the iPhone. https://github.com/hsjunnesson/toes
2013-09-05 23:24:37.777 Prime[4204:c07] 1
2013-09-05 23:24:37.779 Prime[4204:c07] 0.732028842267092
2013-09-05 23:24:37.780 Prime[4204:c07] 0.2530017011838238
2013-09-05 23:24:37.781 Prime[4204:c07] 0.22892546997679017
2013-09-05 23:24:37.781 Prime[4204:c07] 0.5423003204364027
2013-09-05 23:24:37.782 Prime[4204:c07] 0.6065306597126334
2013-09-05 23:24:37.783 Prime[4204:c07] 0.44399788140114904
2013-09-05 23:24:37.783 Prime[4204:c07] 0.15345314921321815
2013-09-05 23:24:37.784 Prime[4204:c07] 0.13885046809469812
2013-09-05 23:24:37.784 Prime[4204:c07] 0.32892187595578626
@c-spencer
c-spencer / core.clj
Last active December 23, 2015 02:49
Simple demo of type construction from Datomic with core.typed and a little glue
(defn create-type
"Extract a type from provided field idents stored in Datomic database at uri."
[uri type-name overrides]
(let [c (d/connect uri)
d (d/db c)
datomic-type-map {:db.type/string 'String
:db.type/ref 'Any}
mt (dt/q> :- [EntityID]
'[:find ?e
:in $ ?t-name
@nz
nz / named pipe queues.sh
Created October 9, 2013 05:31
Nerd sniped by named pipes
#!/bin/sh
# clear old pipe and lock
rmdir worklock 2>/dev/null
rm work
if [[ ! -p work ]]; then
mkfifo work
else
dd if=work of=/dev/null