Skip to content

Instantly share code, notes, and snippets.

(def card-values {2 1 3 1 4 1 5 1 6 1 7 0 8 0 9 0 10 -1 :j -1 :q -1 :k -1 :a -1})
(defn count-cards [counter played-cards]
(if (empty? played-cards)
counter
(count-cards (+ counter (card-values (first played-cards))) (rest played-cards))))
;; counter: 0
;; cards: [4 5 6 :j :q 9 2]
;; counter: 1

Pairing Station How-To

  1. Put your laptop on the stand
  2. Plug in Apple power cable
  3. Plug in white Thunderbolt display adapter
  4. Plug in black USB
  5. Wait 15 seconds
  6. 🤘 Do programming 🤘
## N^2
stock_prices = [70,23,100,34,12,55,8,90,66,2,56,65]
stock_prices.flat_map.with_index do |buy,i|
stock_prices[(i+1)..-1].map do |sell|
{:buy => buy, :sell => sell, :profit => sell - buy}
end
end.max_by { |h| h[:profit] }
## N
def profit(spread)
@worace
worace / open_cl.clj
Created December 12, 2015 00:20
OpenCL from clojure
(ns open-cl-playground.core
(import [com.nativelibs4java.opencl.JavaCL]
[com.nativelibs4java.opencl.CLMem.Usage.*]
[com.nativelibs4java.opencl.CLMem.Usage]
[com.nativelibs4java.opencl.CLDevice.QueueProperties]
[org.bridj.Pointer.*]
))
(defn create-context []
(com.nativelibs4java.opencl.JavaCL/createBestContext))
@worace
worace / gist:e01d57fc2842187831df
Created December 9, 2015 18:18
gametime diff
diff --git a/resources/public/test.html b/resources/public/test.html
index 48257a1..4dacb86 100644
--- a/resources/public/test.html
+++ b/resources/public/test.html
@@ -6,7 +6,8 @@
<link id="favicon" rel="shortcut icon" type="image/png" href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAIElEQVQ4T2NMS0v7z0ABYBw1gGE0DBhGwwCYh4ZBOgAAcQUjIUXh8RYAAAAASUVORK5CYII=" />
</head>
<body>
- <!-- Hidden #app div serves as target for loading the app.
+ <canvas id='target' width='500' height='500'></canvas>
@worace
worace / hotload.markdown
Created December 4, 2015 21:31
Hotloading Dependencies in Leiningen with refactor-nrepl

Hotloading Deps in Lein

Refactor nrepl makes it possible to hotload a dependency into lein without rebooting the repl. This is awesome but it's not super well documented.

First, make sure you have the plugin installed by adding it to the :plugins key of your lein profile. This can be done per project in project.clj, but is probably best to include in your ~/.lein/profiles.clj

Here's an example:

McCormick New Machine and Programming Intro Notes

Reading this Document

This file is written using a format called Markdown, which is a special text format used for generating HTML without having to actually write HTML.

Markdown is fairly readable as text, but you can get a better view of it by "rendering" it into HTML, which can fortunately

(ns block-chain.core
(:require [cheshire.core :as json])
(import [java.net DatagramSocket
MulticastSocket
DatagramPacket
InetAddress
InetSocketAddress]))
;; backchannel
;; MULTICAST_ADDR = "224.6.8.11"
class EnrollmentRepository
def initialize(records = [])
@records = []
end
end
class DistrictRepository
def initialize(repos = {})
@enrollment_repository = repos[:enrollment_repository] || EnrollmentRepository.new
create_districts!
worace @ sha-1 ➸ pry
[1] pry(main)> require "digest"
=> true
[2] pry(main)> key = "calzone"
=> "calzone"
[3] pry(main)> Digest::SHA1.hexdigest(key)
=> "3aa0a0c50683e61c1f81584b1082e11c924535e0"
[4] pry(main)> Digest::SHA1.hexdigest(key).to_i(16)
=> 334703588949583183218034173573122019749278332384
[5] pry(main)> Digest::SHA1.hexdigest(key).to_i(16).to_s(2)