Skip to content

Instantly share code, notes, and snippets.

@uris77
uris77 / clojure_filter_trick.md
Last active October 6, 2015 01:59
Clojure trick

Naive way to filter a list of maps in clojure:

(defn matches-addresses? [addresses]
  (fn [it]
    (lazy-seq  (loop [as addresses
                      acc [(quote or)]]
                 (if (seq (first as))
                   (recur (rest as) (conj acc (lazy-seq [(quote =) (first as) (get it :private-ip-address)])))
                   acc)))))
@uris77
uris77 / 00_destructuring.md
Last active August 29, 2015 14:25 — forked from john2x/00_destructuring.md
Clojure Destructuring Tutorial and Cheat Sheet

Clojure Destructuring Tutorial and Cheat Sheet

(Related blog post)

Simply put, destructuring in Clojure is a way extract values from a datastructure and bind them to symbols, without having to explicitly traverse the datstructure. It allows for elegant and concise Clojure code.

Vectors

@uris77
uris77 / Emacs_paredit.md
Last active August 29, 2015 14:24
Emacs + paredit
  • Copy and paste a sexp:
;;; C-M-SPC (select sexp)
;;; C-w (copy
;;; C-y (to paste)
(defn some-func []
 ;;;
 )
@uris77
uris77 / tweetBot.js
Created March 6, 2015 03:21
Twitter bot
var Twit = require('twit');
var config = require('./config');
var T = new Twit(config);
var stream = T.stream('statuses/filter', {track: '#ngconf'});
stream.on('tweet', function(tweet) {
console.log('Incoming Tweet');
if(!tweet.in_reply_to_user_id && tweet.user.screen_name !== 'freethejazz') {
@uris77
uris77 / Intellij Shortcuts
Last active August 29, 2015 14:07
Intellij Shortcuts
Class: Cmd + N
File: Cmd + Shift + N
Symbol: Cmd + Shift + Alt + N
Declaration: Cmd + B
Declared Type: Ctrl + Shift + B
View Implementation: Cmd + Alt + B
Surround With: Cmd + Alt + T
Debug: Shift + F9
@uris77
uris77 / similar_names.sml
Created August 5, 2014 14:48
Example ML: finds all strings in a list that match full_name.
(* I may be wrong. I'm still an ML newbie. *)
(* Example of something that does not require a unit test. This will only compile of the types align. Traditional TDD is a little *)
(* difficult to do with this. However, I think QuickCheck tests are more suited since it is purely functional. *)
fun similar_names(lst, full_name) =
let val {first=first_name, middle=middle_name, last=last_name} = full_name
in
let fun arrange(lst', acc) =
case lst' of
[] => acc
@uris77
uris77 / CudaTest.coffee
Last active August 29, 2015 13:55
Suggestion Refactor
@Cuda.module "Login", (Login, App, Backbone, Marionette, $, _) ->
# Login Form
class Login.Form extends Marionette.Layout
initialize: (options) ->
@model = new Backbone.Model({error: ""})
@model.bind('change', @render)
handleSubmit: ->
$form = $(e.currentTarget)
@uris77
uris77 / Controller.js
Created January 7, 2014 20:42
marionette ex
define([
'jquery',
'marionette',
'models/product',
'models/product_property_value',
'models/product_property',
'hbs!template/product_detail/detail',
'hbs!template/product_detail/edit_string',
'collections/product_property_values',
'collections/newsfeed_items',
updateMessageFull: function(model) {
var newModel = this.msgDetail.model;
newModel.get('message').set({'id': model.get('id')});
var promise = Q.when(newModel.fetch())
getUserModel(model.get('id')).done(function(model){
this.msgDetail.setModel(newModel);
});
});
docco: {
appA: {
src: ['src/js/appA/file1.js', 'src/js/appA/file2.js']
options: {
output: 'docs/appA/'
}
},
appB: {
src: ['src/js/appB/file1.js', 'src/js/appB/file2.js']
options: {