Skip to content

Instantly share code, notes, and snippets.

(let [won-subboard (fn [board]
(let [all-equal (fn [v] (and (apply = v) (first v)))]
(or
; horizontal lines
(all-equal (subvec board 0 3))
(all-equal (subvec board 3 6))
(all-equal (subvec board 6 9))
; vertical lines
(all-equal (vals (select-keys board [0 3 6])))
(all-equal (vals (select-keys board [1 4 7])))
@jamesnvc
jamesnvc / recursion.clj
Created November 11, 2015 16:18
Functional Programming demo
(defn rtake
[n lst]
(if (= n 0)
()
(cons (first lst)
(rtake (dec n) (rest lst)))))
(def my-first (partial rtake 1))
(defn rzip
@jamesnvc
jamesnvc / update.m
Created October 30, 2015 17:19
SpriteKit update function
-(void)update:(CFTimeInterval)currentTime {
static CFTimeInterval lastObstacleAt = 1;
static CFTimeInterval pausedLoopAt;
if (self.paused) {
if (!pausedLoopAt) {
pausedLoopAt = currentTime;
}
return;
} else if (pausedLoopAt) {
lastObstacleAt += currentTime - pausedLoopAt;
@jamesnvc
jamesnvc / functional.swift
Created September 16, 2015 15:19
Intro to functional programming
//: Playground - noun: a place where people can play
import UIKit
func makeIncr() -> (Int -> Int) {
var x = 0
return { y in x += y; return x }
}
let inc1 = makeIncr()
@jamesnvc
jamesnvc / just_functional_things.swift
Created July 27, 2015 14:47
Functional programming lecture code
// closures
func makeIncr() -> (Int -> Int) {
var n = 0
return { x in n += x; return n }
}
let inc1 = makeIncr()
let inc2 = makeIncr()
println("inc1 +1 \(inc1(1))")
println("inc2 +1 \(inc2(1))")
set spacenumber to 9
tell application "System Events"
set _desktops to every desktop
if (count of _desktops) > 1 then
-- if you have multiple displays (eg: external monitor) ask which
display dialog "Choose your screen." buttons (get display name of every desktop) default button 1
set _display to the button returned of the result
else
-- else set the one display as selected
@jamesnvc
jamesnvc / testing.clj
Created September 8, 2014 02:13
Testing keywords compare
(import '(javax.script ScriptEngineManager))
(defn eval-js
[js]
(let [engine (.getEngineByName (ScriptEngineManager. ) "nashorn")]
(.eval engine js)))
(require '[cljs.closure :as cljsc])
(eval-js
#!/usr/bin/env python2.7
"""To use:
First, run `pip install python-twitter`
Then, you'll need to create a twitter application at apps.twitter.com. This
will give you the API key & secret. Set its permissions to be Read & Write.
Then you'll generate an access token on the same page and put all four values
in the appropriate variables below.
Once that's done, just run ./twitter_autoblock_rts.py <some-tweet-id>
### Keybase proof
I hereby claim:
* I am jamesnvc on github.
* I am jamesnvc (https://keybase.io/jamesnvc) on keybase.
* I have a public key whose fingerprint is 1E7B 141B CF59 912A 5CEC 751D FCEE 8906 8DC9 A386
To claim this, I am signing this object:
(require '[datomic.api :as d])
(d/create-database "datomic:mem://example")
(def conn (d/connect "datomic:mem://example"))
(d/transact conn
[{:db/id #db/id [:db.part/db -1]
:db/ident :foo
:db/valueType :db.type/string
:db/cardinality :db.cardinality/one
:db.install/_attribute :db.part/db}