Skip to content

Instantly share code, notes, and snippets.

@kopasetik
kopasetik / package.json
Created February 5, 2016 07:58
npm configuration for live-reload with a build every save
{
"name": "caravan",
"version": "1.0.0",
"description": "travel awesome",
"main": "./lib/index.js",
"config": {
"sass_command": "./node_modules/node-sass/bin/node-sass"
},
"scripts": {
"test": "npm run test",
@kopasetik
kopasetik / js_default_values.js
Created January 25, 2016 19:22
Javascript destructuring with default values
// destructuring and default values
const give_discount = ({item, price, percent_discount=10})=>{
console.log('For the ' + item + ' listed at $' + price +
', you get ' + percent_discount + '% off!')
}
give_discount({item: 'sweater', price: 200, percent_discount: 25})
//=> For the sweater listed at $200, you get 25% off!
give_discount({item: 'dress shoes', price: 350})
@kopasetik
kopasetik / js_elision_destructuring.js
Created January 21, 2016 20:54
Javascript destructuring and elision
// elision AKA skipping array elements
let [b, , , , , a] = ['Robin!', 'Nana', 'nana', 'nana', 'nana', 'Batman!']
console.log(a) //=> Batman!
console.log(b) //=> Robin!
@kopasetik
kopasetik / clj_elision_destructuring.clj
Last active January 21, 2016 20:54
Clojure destructuring and elision
(def jokers-challenge ["Robin!" "Nana" "nana" "nana" "nana" "Batman!"])
; elision AKA destructuring that skips vector items
(let [[b _ _ _ _ a] jokers-challenge]
(println a)
(println b))
;=> Batman!
;=> Robin!
@kopasetik
kopasetik / js_rest_operator.js
Created January 21, 2016 20:49
Javascript rest operator
// rest operator example
const print_the_rest = ([a, b, ...remaining_values]) => remaining_values.map(item => console.log(item))
print_the_rest(["celebration", "can you feel it", "fantasy", "september", "boogie wonderland", "getaway"])
//=> fantasy
//=> september
//=> boogie wonderland
//=> getaway
@kopasetik
kopasetik / clj_rest_operator.clj
Created January 21, 2016 20:48
Clojure rest operator
; rest operator example
(defn print-the-rest
;prints the rest of the collection
[[a b & remaining-values]]
(doall (map println remaining-values)))
(print-the-rest ["celebration" "can you feel it" "fantasy" "september" "boogie wonderland" "getaway"])
;=> fantasy
;=> september
@kopasetik
kopasetik / js_json_destructuring.js
Created January 21, 2016 20:46
Javascript JSON destructuring
const request = require('request')
const isMovie = (item) => {
if (item.Type === "movie") return true
return false
}
const movies = request('http://omdbapi.com/?s=highlander',
((err, res, body) => {
@kopasetik
kopasetik / clj_json_destructuring.clj
Created January 21, 2016 20:45
Clojure JSON destructuring
(ns clojure-noob.core
(:gen-class)
(:require [clojure.data.json :as json]
[clojure.pprint :as pp]))
(defn get-url
"get a url's content"
[url]
(-> url
slurp
@kopasetik
kopasetik / js_function_destructuring.js
Last active February 8, 2016 21:45
Javascript function destructuring
// function destructuring
const eat_pizza_picky_style = ({dough, sauce, meat}) => {
console.log('For this pizza, Whiskers only eats the '
+ dough + ', ' + sauce + ', and ' + meat
+ '. It picks everything else off!')
}
const pepperoni_pizza = {
cheese: 'mozzarella',
dough: 'white flour dough',
@kopasetik
kopasetik / clj_function_destructuring.clj
Last active February 8, 2016 21:43
Clojure function destructuring
; function destructuring
(defn eat-pizza-picky-style
; for eating only the good stuff from a pizza
[{:keys [dough meat sauce]}]
(println (str
"For this pizza, Whiskers only eats the "
dough ", " meat ", and " sauce
". It picks everything else off!")))
(def pepperoni-pizza {