Skip to content

Instantly share code, notes, and snippets.

View icambron's full-sized avatar

Isaac Cambron icambron

View GitHub Profile
<pre><code class="language-js">moment().subtract(<span class="number">10</span>, <span class="string">'days'</span>).calendar();<span class="comment"> // ٩/&rlm;٨/&rlm;٢٠١٦</span>
moment().subtract(<span class="number">6</span>, <span class="string">'days'</span>).calendar(); <span class="comment"> // السبت عند الساعة ٢٠:٣٠</span>
moment().subtract(<span class="number">3</span>, <span class="string">'days'</span>).calendar(); <span class="comment"> // الثلاثاء عند الساعة ٢٠:٣٠</span>
moment().subtract(<span class="number">1</span>, <span class="string">'days'</span>).calendar(); <span class="comment"> // أمس عند الساعة ٢٠:٣٠</span>
moment().calendar(); <span class="comment"> // اليوم عند الساعة ٢٠:٣٠</span>
moment().add(<span class="number">1</span>, <span class="string">'days'</span>).calendar(); <span class="comment"> // غدًا عند الساعة ٢٠:٣٠</span>
moment().add(<span class="number">3</span>, <span class="string">'days'</span>).calendar(); <span class="comment"> // الإثنين عند
@icambron
icambron / dateUTC.js
Created April 5, 2016 00:40
Fun with proxies
function dateUTC(date, offset = 0){
let d = new Date(date),
adjust = (dir, item) => offset == 0 ? item : new Date(+item + offset * 60 * 1000 * -dir),
shift = (v) => {s = adjust(1, d);
return v;},
unshift = (v) => {d = adjust(-1, s);
return v;},
rewrites = {
getFullYear: () => s.getUTCFullYear(),
@icambron
icambron / gist:5d969958b2d51899ce42
Last active August 29, 2015 14:24
WTF transients?
;; a big list of urls
(def furls ["support.google.com" "docs.google.com" "wwwapps.ups.com" "www.twitter.com" "careers.stackoverflow.com" "careers.stackoverflow.com" "careers.stackoverflow.com" "support.google.com" "docs.google.com" "support.office.com" "salesforce.com" "tryscratch.com" "gist.github.com" "gist.github.com" "gist.github.com" "www.zensight.co" "gist.github.com" "gist.github.com" "www.linkedin.com" "gist.github.com" "www.amazon.com" "gist.github.com" "gist.github.com" "www.joyofclojure.com" "gist.github.com" "gist.github.com" "www.linkedin.com" "www.joyofclojure.com" "gist.github.com" "gist.github.com" "gist.github.com" "gist.github.com" "www.linkedin.com" "www.linkedin.com" "www.linkedin.com" "gist.github.com" "clojure.org" "clojure.org" "clojure.org" "clojure.org" "gist.github.com" "gist.github.com" "gist.github.com" "www.google.com" "gist.github.com" "www.google.com" "www.google.com" "gist.github.com" "gist.github.com" "www.google.com" "gist.github.com" "careers.stackoverflow.com" "meta.stacke
dev=> (defn foo [] (async/go 5))
#'dev/foo
dev=> (defn bar [] (fn [] (async/go (apply #(inc (async/<! (foo)))))))
CompilerException java.lang.IllegalArgumentException: No method in multimethod '-item-to-ssa' for dispatch value: :fn, compiling:(/private/var/folders/xr/sn8c5pb14yb6srt18k_jhdj00000gn/T/form-init9020384603647184494.clj:1:21)
(defn eat-well [vendors]
(loop [[[item & others] newest older oldest] [vendors 0 0 0]]
(if item
(recur [others (+ item (max older oldest)) newest older])
(max newest older oldest))))
(eat-well [1 4 3 12 4 3 3 4])
@icambron
icambron / Commands
Created July 17, 2014 03:43
vagrant docker-run and env variables
#confirms env variable is set in container
vagrant docker-run -- sh -c 'exec env | grep DB_PORT_5432_TCP_PORT'
#can't echo env variable because evaluated on VM host
vagrant docker-run -- sh -c 'echo $DB_PORT_5432_TCP_PORT'
#can't connect to psql because of that
vagrant docker-run db -- sh -c 'exec psql -h $DB_PORT_5432_TCP_ADDR -p $DB_PORT_5432_TCP_PORT -U postgres'
@icambron
icambron / gist:a2b4f8d5942b811f4c07
Last active August 29, 2015 14:03
Slicker quicksort in coffee
#adapted from The Joy of Clojure, second edition, page 132-135
quicksort = (array) ->
split = (work) ->
[part, parts...] = work
if part?
if part.length
[pivot, xs...] = part
split([
(x for x in xs when x < pivot),
pivot,

Edit: Nevermind, the 3 branch seems to work here. I must have been wrong in thinking 3-wip was working for me in other circumstances.

I'm trying to cheat a bit and steal some of the SASS files from 3-wip branch of bootstrap-sass. When wired into my Minuteman asset pipeline, that branch works fine, but when I pull out specific files I can't compile them:

isaac@ironhide [04:00:13] [~/code/jquery-simple-datetimepicker] [master *]
-> % scss vendor/bootstrap-sass/vendor/assets/stylesheets/bootstrap/_mixins.scss
Syntax error: Invalid CSS after "...dropdown-toggle": expected "{", was "& {"

 "&amp;" may only be used at the beginning of a compound selector.
@icambron
icambron / gist:5556420
Last active December 17, 2015 05:18
Trying to use chef-rvm with vagrant

I'm trying to figure out why vagrant w/chef-solo + chef-rvm isn't working for me. Here's how I think it's supposed to work:

  1. You tell chef where chef-solo is installed on the vagrant image
  2. The rvm:vagrant recipe creates a wrapper script, also called chef-solo, that does this: a. set an environment variable overriding the current ruby to "system" b. calls chef-solo as specified in the attributes c. it goes on the path before the real chef-solo does
  3. the rvm:system recipe installs rvm and your specified ruby system-wide
  4. Now, the next time you do a vagrant up, chef-solo (which is now actually the wrapper script) will still work because it's using the system-installed ruby, which has access to the chef-solo gem, as opposed to your newly installed Ruby, which doesn't.
@icambron
icambron / gist:3022005
Created June 30, 2012 03:16
Quicksort in Coffeescript
# Quicksort in CoffeeScript.
# I wrote this because I'd honestly forgotten how quicksort worked, and it troubled me.
quicksort = (array) ->
# Utility - swap the values at two indexes, but only if the values are different.
swap = (index_0, index_1) ->
[val_0, val_1] = [array[index_0], array[index_1]]
[array[index_0], array[index_1]] = [val_1, val_0] unless val_0 == val_1
# Divide a subset of the array (values between left and right, inclusive) into two partitions based on whether