Skip to content

Instantly share code, notes, and snippets.

@Risto-Stevcev
Risto-Stevcev / app.js
Created November 27, 2014 09:16
Checkbox list directive
var app = angular.module('app', []);
app.controller('TodoCtrl', function($scope) {
$scope.foo = true;
$scope.bar = false;
$scope.baz = true;
$scope.baa = true;
$scope.checkboxes = {
'foo': $scope.foo,
'bar': $scope.bar,
@Risto-Stevcev
Risto-Stevcev / CSVMapper.java
Created November 27, 2014 10:47
CSV aggregator in Java
import java.io.BufferedReader;
import java.io.StringReader;
import java.util.HashMap;
public class CSVMapper {
public String transformCsv (String csvFile) {
return csvMapToString(getCsvMap(csvFile));
}
private HashMap<String, Integer[]> getCsvMap (String csvFile) {
@Risto-Stevcev
Risto-Stevcev / Main.hs
Created December 6, 2014 02:19
Adding HUnit to Cabal packages
module Main where
main = undefined
@Risto-Stevcev
Risto-Stevcev / dynamic.html
Created December 6, 2014 03:51
Dynamically loading javascript
<span class="foo">bar</span>
@Risto-Stevcev
Risto-Stevcev / Gruntfile.js
Created March 5, 2015 20:46
Protractor issue #1895 - Cannot start webdriver as a process
module.exports = function(grunt) {
grunt.initConfig({
foo: {
bar: {
options: {}
}
}
})
grunt.loadTasks('tasks')
@Risto-Stevcev
Risto-Stevcev / factorial.clj
Last active August 29, 2015 14:23
Loop-recur TCO for self-referencing
;;;; Partial Tail Call Optimization in Clojure
;; See this for why no full implicit TCO: https://groups.google.com/forum/#!msg/clojure/4bSdsbperNE/tXdcmbiv4g0J
; Naive non-optimized tail-recursive factorial function
(defn naive-factorial
([n] (naive-factorial n 1))
([n acc]
(if (zero? n)
acc
(naive-factorial (- n 1) (* acc n)))))
@Risto-Stevcev
Risto-Stevcev / fo-func.clj
Created June 17, 2015 21:49
First-order functions
(defn callfn [f & args]
(apply f args))
(callfn + 1 2 3 4)
; returns 10
@Risto-Stevcev
Risto-Stevcev / ncproxy.sh
Created July 14, 2015 07:43
Netcat HTTP proxy
mkfifo mypipe; nc -l 8089 < mypipe | tee inflow | nc www.google.com 80 | tee outflow > mypipe; rm mypipe
-- In GHCi
:set +m
let x y = x y
-- ex: x 2 will loop infinitely
:{
let {
z y = y
where
t = x 2
@Risto-Stevcev
Risto-Stevcev / autocomplete.js
Created July 31, 2015 13:00
Javascript depdendency-free autocomplete
var items = ['Cheese, blue', 'Cheese, cheshire', 'Avocadoes, raw'];
$('.food-input').keyup(function(event) {
if (event.key.match(/^[a-zA-Z0-9, -]{1}$/g)) {
var inputVal = event.target.value;
var match = items.filter(function(item) {
return item.match(new RegExp('^'+ inputVal +'.*', 'g'));
});
if (match.length > 0) {
event.target.value = match[0];