Skip to content

Instantly share code, notes, and snippets.

View juliangruber's full-sized avatar

Julian Gruber juliangruber

View GitHub Profile
const http = require('http')
http.createServer((req, res) => {
res.write('<!DOCTYPE html><html><head><title>electron-stream</title><script>')
res.write('console.log("hi");\n')
setTimeout(() => {
res.write('console.log("you");\n')
res.end('</script></head></html>')
}, 3000)
}).listen(8000, () => console.log('8000'))
{ name: 'sillytest',
time:
{ modified: '2016-08-12T20:24:05.671Z',
created: '2016-04-04T16:39:05.573Z',
'1.0.0': '2016-04-04T16:39:05.573Z',
'1.0.1': '2016-04-04T16:42:05.213Z',
'1.0.2': '2016-04-04T16:42:24.049Z',
'1.0.3': '2016-04-04T16:42:52.291Z',
'0.0.1': '2016-08-12T20:19:52.345Z',
'0.0.2': '2016-08-12T20:20:08.997Z',
@juliangruber
juliangruber / render.js
Last active June 13, 2016 12:08
yo-yo + es6 = ❤️
const yo = require('yo-yo')
module.exports = entries => yo`
<ul>
${entries.map(entry => yo`
<li>${entry.name}</li>
`)}
</ul>`
@juliangruber
juliangruber / extend.plist
Created May 30, 2016 20:30
Here is how to accept custom protocol links like dat://LINK in an @electronjs app, in osx. For this to work you need to properly package the app into a `.app`, and place the CFBundleURLTypes spec into it's Info.plist. Then, move the app into another directory using Finder (!). Here we're using electron-packager.
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLName</key>
<string>Dat Link</string>
<key>CFBundleURLSchemes</key>
<array>
<string>dat</string>
</array>
</dict>
@juliangruber
juliangruber / gist:8088601
Created December 22, 2013 21:22
pkginit
{
"name" : basename.replace(/^node-/, ''),
"description" : prompt(),
"version" : "0.0.0",
"repository" : {
"type" : "git",
"url" : "git://github.com/juliangruber/" + basename + ".git"
},
"homepage": "https://github.com/juliangruber/" + basename,
"main" : prompt('entry point', 'index.js'),
$ sudo npm i -g module-usage
$ module-usage redis
acl (package/test/runner.js)
var Redis = require('redis');
acl (package/test/runner.js)
redis = Redis.createClient(options.port, options.host, { no_ready_check: true })
Array.prototype.forEach.call(document.querySelectorAll('#tracks li div'), function(track) {
track.addEventListener('click', function(e) {
e.preventDefault();
var lyrics = e.target.parentNode.querySelector('p');
lyrics.style.display = lyrics.style.display == 'none'
? 'block'
: 'none';
});
});
@juliangruber
juliangruber / gist:7504604
Last active December 28, 2015 12:59
inner product
// inner product, functional, varargs, as in http://www.stanford.edu/class/cs242/readings/backus.pdf (1)
function inner() {
return transpose(slice(arguments)).map(multiply).reduce(add, 0);
}
function transpose(arr) {
return arr[0].reduce(function(acc, el, i) {
return acc.concat(el.reduce(function(_acc, _el) {
acc.push(_el[i]);
@juliangruber
juliangruber / gist:7356625
Last active December 27, 2015 16:39
setup custom local.host

So you might have set up dnsmasq with this tutorial but then you notice that you can't set cookies to subdomains of localhost or for all of localhost's subdomains (see why).

So we set up a custom "localhost", that I'll call local.host, but you can pick whatever you want, as long as it contains at least one dot. Just adapt the first two commands.

$ # add to hosts list
$ sudo echo "127.0.0.1 local.host" >> /private/etc/hosts
$ # tell your dns server about it
@juliangruber
juliangruber / gist:7337388
Created November 6, 2013 14:57
browserify bundling tests
# simple bundle
$ time browserify --debug lib/boot/index.js | wc -c
1397809
real 0m1.726s
user 0m1.540s
sys 0m0.139s
# bundle without node_modules