Skip to content

Instantly share code, notes, and snippets.

@gerhardberger
gerhardberger / zipWith
Created March 31, 2012 22:08
zipWith function for JavaScript.
zipWith = function() {
var args = Array.prototype.slice.call(arguments)
, ls = _.initial(args)
, ls_
, f = _.last(args)
ls_ = _.zip.apply(this, ls)
ls_ = _.map(ls_, function(x) {
return f.apply(this, x)
})
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Input Merge</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript">
!function($) {
@gerhardberger
gerhardberger / merge.js
Created August 31, 2012 11:44
High-order merge function.
// High-order merge function.
// Dependency: underscore.js [http://underscorejs.org]
// Demo: http://jsfiddle.net/7HB8J/
// First argument: Function (returns a Boolean, that decides, wether it is the same (hence can be overwritten))
// Rest: Array(s)
merge = function (f) {
var as = _.flatten(Array.prototype.slice.call(arguments, 1)).reverse().map(function (a) { return {v: a, uniq: 0}; });
return as.map(function (a) {
@gerhardberger
gerhardberger / s2error
Created September 6, 2014 14:37
s2 install on nodejitsu
> s2@0.3.9 install /root/tmp/tmp-68480uf9w6tc/build/package/node_modules/level-nearby/node_modules/s2
> node-pre-gyp install --fallback-to-build
node-pre-gyp http GET https://mapbox-node-binary.s3.amazonaws.com/s2/v0.3.9/node-v11-sunos-x64.tar.gz
node-pre-gyp http 403 https://mapbox-node-binary.s3.amazonaws.com/s2/v0.3.9/node-v11-sunos-x64.tar.gz
node-pre-gyp http 403 status code downloading tarball (falling back to source compile with node-gyp)
make: Entering directory `/root/tmp/tmp-68480uf9w6tc/build/package/node_modules/level-nearby/node_modules/s2/build'
CXX(target) Release/obj.target/_s2/src/latlng.o
In file included from /opt/local/include/c++/unordered_map:35:0,
from ../geometry/s2.h:12,
// mw.js
var mw = function (options) {
return function *(next) {
this.db = options.db;
yield next;
}
}
@gerhardberger
gerhardberger / hello.js
Created January 27, 2016 12:28
child process testing
'use strict'
const minwhere = require('minwhere')
const test = require('tapes')
const exit = require('exit')
const cache = minwhere.resourceCache
test('Overall cache test', t => {
cache.on('ready', () => {
Process: Electron [52076]
Path: /usr/local/lib/node_modules/electron-prebuilt/dist/Electron.app/Contents/MacOS/Electron
Identifier: com.github.electron
Version: 0.36.7 (0.36.7)
Code Type: X86-64 (Native)
Parent Process: node [52075]
Responsible: Terminal [45646]
User ID: 501
Date/Time: 2016-02-03 19:18:36.761 +0100
# 1.3
iptables -A INPUT --source 10.0.2.0/24 --protocol tcp --dport 22 -j ACCEPT
iptables -A INPUT --source 127.0.0.0/8 --protocol tcp --dport 22 -j ACCEPT
iptables -A INPUT --protocol tcp --dport 22 -j DROP
# 1.4
iptables -A INPUT --protocol icmp -j DROP
# 1.5
sudo adduser gellert
// $ node --harmony_destructuring match.js -5
'use strict'
let x = Number(process.argv[2])
let { true: a } = {
[ x > 0 ]: 1,
[ x < 0 ]: -1,
[ x === 0 ]: 'wow'
}
$ npm install
$ npm run native
$ npm run wrappers
$ npm test