Skip to content

Instantly share code, notes, and snippets.

View lauripiispanen's full-sized avatar

Lauri Piispanen lauripiispanen

View GitHub Profile
================================================================================
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
@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...
(function() { var names = document.querySelectorAll("td.name"); console.log(names[Math.floor(Math.random() * names.length)].innerText) })();
@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.",
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"
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'
.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)
(function() {
return
"a"
})()
>>> undefined
(function() {
return "a"
})()
@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;
}
@lauripiispanen
lauripiispanen / gist:5410636
Created April 18, 2013 06:36
Towtruck websocket data example
» curl -i -N -H "Sec-WebSocket-Version: 13" -H "Sec-WebSocket-Key: [hidden]" -H "Connection: Upgrade" -H "Upgrade: websocket" -H "Host: hub.towtruck.mozillalabs.com" -H "Origin: https://towtruck.mozillalabs.com" http://hub.towtruck.mozillalabs.com/hub/[sessionId]
HTTP/1.1 101 Switching Protocols
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Accept: [A token]
Origin: https://towtruck.mozillalabs.com
{"type":"cursor-update","element":"body:nth-child(2):nth-child(1)","offsetX":1152,"offsetY":868,"clientId":"aKgBnNEpbn"}
{"type":"cursor-update","element":"body:nth-child(2):nth-child(1)","offsetX":1103,"offsetY":766,"clientId":"aKgBnNEpbn"}