This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var gulp = require('gulp'); | |
var nodemon = require('gulp-nodemon'); | |
var del = require('del'); | |
// server | |
var babel = require('gulp-babel'); | |
// client | |
var browserify = require('browserify'); | |
var babelify = require('babelify'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;;; compiled using `buildapp --output hello --entry main --load hello-labs.lisp` | |
;;;; run using ./hello http://labs.sent1nel.me | |
(load "/home/sent1nel/quicklisp/setup.lisp") | |
(ql:quickload "drakma") | |
(defun main (argv) | |
(multiple-value-bind (body-or-stream status-code) | |
(drakma:http-request (nth 1 argv)) | |
(format t "~s~%" body-or-stream) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> var o = new Object(); | |
undefined | |
> o | |
{} | |
> o.hasOwnProperty('test'); | |
false | |
> o.test = 'testing!'; | |
'testing!' | |
> o.hasOwnProperty('test'); | |
true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# binding values to 'this' via `fn.call()` and `fn.apply()` | |
> var person = { name: 'sent1nel' } | |
> (function print(){ console.log(this.name); }).call(person); | |
sent1nel | |
> (function print(){ console.log(this.name); }).apply(person); | |
sent1nel | |
# passing in args in addition to the bound scope | |
# the difference between `fn.call()` and `fn.apply()` is that | |
# apply accepts an array of arguments instead of a list |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# repl | |
cljs.user> (defn greet [name] (.log js/console (str "Hello, " name "!"))) | |
cljs.user> (greet "Sent1nel") | |
Hello, Sent1nel! | |
# shell, using clojure1.6 from debian project | |
zipp@stormwind:~/clojure$ cat hello.clj | |
(defn greet [name] | |
(if-not (clojure.string/blank? name) | |
(println (str "Hello, " name "!")) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(require '[clojure.string :as s]) | |
(defn palindrome | |
[text] | |
(= (s/reverse text) text)) | |
user=> (palindrome "foo") | |
false | |
user=> (palindrome "lol") | |
true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; currying! returns a partially evaluated function | |
(defn dice [size] (fn [] (+ 1 (rand-int size)))) ;; idiomatic vs using a rand formula | |
(def d20 (dice 20)) | |
(defn roll-die-until-twenty | |
([die] (roll-die-until-twenty die 1)) ;; multiple arity | |
([die attempt] | |
(let [roll (die)] ;; scoped binding, available only in this lexical scope | |
(cond ;; https://clojuredocs.org/clojure.core/cond |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; allowing me to use a field name of my choice | |
;; shouldn't require so much boilerplate | |
(ns app.friend | |
(:require [app.db.core :as db] | |
[cemerick.friend :as friend] | |
(cemerick.friend [workflows :as workflows] | |
[credentials :as creds]) | |
[ring.util.request :as request] | |
[ring.util.response :refer [response redirect status]] | |
[compojure.core :refer [defroutes]] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
user=> (defn ls [dir] (seq (.list (clojure.java.io/file dir)))) | |
#'user/ls | |
user=> (ls "microdungeon") | |
("monster.h" "map.c" "ex17.c" ".git" ".gitignore" "mud.h" "Makefile" "monster.c" "room.c" "map.h" "room.h" "mud.c") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(def cards [ | |
"%s. High five, bro." | |
"TSA guidelines now prohibit %s on airplanes." | |
"It's a pity that kids these days are all getting involved with %s." | |
"In 1,000 years, when paper money is but a distant memory, %s will be our currency." | |
"Major League Baseball has banned %s for giving players an unfair advantage." | |
"What is Batman's guilty pleasure? %s." | |
"Next from J.K. Rowling: Harry Potter and the Chamber of %s." | |
"I'm sorry, Professor, but I couldn't complete my homework because of %s." | |
"What did I bring back from Mexico? %s." |