Skip to content

Instantly share code, notes, and snippets.

View lauripiispanen's full-sized avatar

Lauri Piispanen lauripiispanen

View GitHub Profile
@lauripiispanen
lauripiispanen / gist:5412081
Created April 18, 2013 11:38
Java y u no lambda? :(
public String getDays() {
String ret = "";
for (int i = 0; i < days.size(); i++) {
if (i > 0) {
ret += ", ";
}
ret += days.get(i);
}
return ret;
}
(function() {
return
"a"
})()
>>> undefined
(function() {
return "a"
})()
.directive 'my-magix-directivix', ['$compile', ($compile) ->
compile: (element, attrs) ->
element.attr("my-other-directive", "and-some-settings")
element.attr("ng-model", "foobar")
element.removeAttr("my-magix-directivix")
element.removeAttr("data-my-magix-directivix")
{
pre: ->
post: ($scope, element) ->
$compile(element)($scope)
cluster = require 'cluster'
settings = require './settings'
log4js = require 'log4js'
port = process.env.PORT || 3000
forks = settings.forks || 1
newrelic =
noticeError: (error) ->
if (settings.newrelic_license)
newrelic = require 'newrelic'
1. Enter "sudo scutil" and press Return
2. Type "list". Look for a key like "State:/Network/Service/com.viscosityvpn.vpn-tun0/DNS"
3. Enter "remove <key" (e.g. " remove State:/Network/Service/com.viscosityvpn.vpn-tun0/DNS")
4. Enter "quit"
@lauripiispanen
lauripiispanen / constraints.js
Last active March 3, 2016 09:18
Clojure-style :pre and :post constraints in ES6 - big thanks to @polytypic for the original idea!
const constrain = ({ pre = () => {}, post = () => {} }) => fn => (...args) => {
const throwIf = x => y => { if (x(y)) { throw x(y) } else return y },
compose = (...args) => args.reduce((x,fn) => (...args) => fn(x.apply(x, args)))
return compose(throwIf(pre), fn.bind(fn, args), throwIf((...a) => post.apply(a.concat(args)))).apply(null, args)
}
const sqrt = constrain(
{pre: x => x < 0 && "Let's go shopping!",
post: (y, x) => y < 0 && "Math is hard."
|| 0.1 < y*y - x && "Floats are harder.",
(function() { var names = document.querySelectorAll("td.name"); console.log(names[Math.floor(Math.random() * names.length)].innerText) })();
@lauripiispanen
lauripiispanen / datalayer-proxy.js
Last active May 25, 2022 14:00
Using ES6 proxies to keep historic data layer state for debug purposes
let dataLayerHistory = []
// this would come from GA
let dataLayer = {
push(obj) {
console.log("pushed to dataLayer", obj)
}
}
// here's our clever little trick...
================================================================================
Model prompt >>> Prime Minister Juha Sipilä's offer for the government to resign
was accepted by President of Finland Sauli Niinistö on Friday. President
Niinistö asked the cabinet to complete its term in office in an administrative
capacity. ======================================== SAMPLE 1 ========================================
The President asked that the government and parliament resign and called on the
president to resign.
The situation was also resolved after the cabinet refused to meet for three days