Skip to content

Instantly share code, notes, and snippets.

(ns your-ride-is-here-test
[:require [clojure.test :refer :all]])
(defn decode [e]
(mod (reduce (fn [total, value] (* total value)) 1 (map (fn [a] (- (int a) 64)) (seq e))) 47)
)
(defn ride [group, comet]
(if (= (decode group) (decode comet)) "GO" "STAY")
)
(ns squared-same-test
(:require [clojure.test :refer :all] [clojure.set :refer :all]) )
(defn function_maps_sets [f, a, b]
(= 0 (count (difference (set b) (set (map f a)))))
)
(defn function_is_map_between_sets [f, a, b]
(def setA (set a))
(def setB (set b))
@fcanas
fcanas / Distance.swift
Created May 21, 2015 15:11
Creating a Numeric Type : Distance
public struct Distance :NumericType {
public var value :Double
public init(_ value: Double) {
self.value = value
}
}
extension Distance :IntegerLiteralConvertible {
public init(integerLiteral: IntegerLiteralType) {
self.init(Double(integerLiteral))
@fcanas
fcanas / gist:d3ff6c49099c38ce36e5
Created May 13, 2015 01:38
UIMandelbrot — Appropriate for Xcode Playgrounds
import UIKit
let white = UIColor.whiteColor().CGColor
let black = UIColor.blackColor().CGColor
let w :CGFloat = 105
let h :CGFloat = 60
let size = CGSizeMake(w, h)
UIGraphicsBeginImageContextWithOptions(size, true, 0.0)
@fcanas
fcanas / gist:39391b6a5670af668862
Last active August 29, 2015 14:20
Shell Game
; To run:
;
; $ lein repl
; $ (load-file "shell_game_test.clj")
(ns the-shell-game-test
(:require [clojure.test :refer :all]))
(defn move-the-ball [position, move]
(nth (concat [position] (reverse move)) (+ 1 (.indexOf move position)))
@fcanas
fcanas / gist:d541b089a03956ae5515
Last active August 29, 2015 14:16
Swift Church Encoding. Barely.
typealias ø = ((Int -> Int) -> Int -> Int)
func i<T>(v :T) -> T {
return v
}
func c<T>(n: Int) -> (T -> T) -> T -> T {
if n == 0 {
return { x in i }
}
@fcanas
fcanas / gist:9a72f1981de4a9a0aa58
Last active August 29, 2015 14:12
Flipping Bits
func flipOn<T: RawOptionSetType>(value: T, change: T) -> T {
return T(rawValue: value.rawValue | change.rawValue )
}
func flipOff<T: RawOptionSetType>(value: T, change: T) -> T {
return T(rawValue: value.rawValue & ~change.rawValue )
}
func toggle<T: RawOptionSetType>(value: T, change: T) -> T {
return T(rawValue: value.rawValue ^ change.rawValue )
@fcanas
fcanas / ButtonSpringBehavior.swift
Last active January 16, 2018 01:56
Button Spring Behavior
import UIKit
var SpringKey :Int = 0
class ButtonSpringBehavior: NSObject {
var scaleFactor :CGFloat = 1.3
init(button: UIButton) {
super.init()
button.addTarget(self, action: #selector(springOut(sender:)), for: UIControlEvents.touchDown)
@fcanas
fcanas / gist:149177d4932f329d92f8
Created September 26, 2014 21:08
In Reaction to Bret Victor's "Inventing on Principle"
# [Bret Victor](http://worrydream.com/)
* [Inventing on Principle](http://www.youtube.com/watch?v=PUv66718DII)
* [The Future of Programming](http://vimeo.com/71278954)
* [Stop Drawing Dead Fish](http://vimeo.com/64895205)
# Doug Engelbart
* [The Mother of All Demos](http://www.youtube.com/watch?v=yJDv-zdhzMY) - 1968 Ridiculousness

Keybase proof

I hereby claim:

  • I am fcanas on github.
  • I am fcanas (https://keybase.io/fcanas) on keybase.
  • I have a public key whose fingerprint is D5AC E5A4 D764 1040 F907 DB29 42DB B883 EBAC E404

To claim this, I am signing this object: