Skip to content

Instantly share code, notes, and snippets.

@nikcorg
nikcorg / blabla.js
Created December 10, 2014 12:15
testing 1...2...3
alert("hello world!");

Step 0:

Get Homebrew installed on your mac if you don't already have it

Step 1:

Install highlight. "brew install highlight". (This brings down Lua and Boost as well)

Step 2:

@nikcorg
nikcorg / README.md
Last active August 29, 2015 14:08
Docked MongoDB helpers

Some scripts for working with Boot2Docker and the Docker mongodb image (https://registry.hub.docker.com/u/dockerfile/mongodb/)

The scripts

mongo-cli.sh opens an interactive mongo shell

mongo-restore.sh will fetch a zip, unpack it and mongorestore a contained dump

prompt.sh will open an interactive shell in the running docker instance

@nikcorg
nikcorg / promisified-hyperquest.js
Last active May 10, 2018 05:44
Promisified Hyperquest -- A quick exercise wrapping Hyperquest in a Promise for an easy thenable API.
var concat = require("concat-stream");
var hyperquest = require("hyperquest");
var Promise = require("bluebird");
var stream = require("stream");
// Wait for the request to finish or fail
function promisify(req) {
return new Promise(function (resolve, reject) {
req.on("error", reject).pipe(concat({ encoding: "string" }, resolve));
@nikcorg
nikcorg / sw.js
Last active August 29, 2015 14:06
Immediately returning response
this.addEventListener('fetch', function(event) {
var cachedResponse = caches.match(event.request).catch(function() {
return event.default().then(function(response) {
// With the assumption that this is an async operation...
// (who reads specs anyway, and besides it's returning a promise)
// ...store the response to the cache in parallel.
caches.get('v1').then(function(cache) {
cache.put(event.request, response.clone());
});
@nikcorg
nikcorg / berlin-jsconf-2014.md
Last active August 4, 2023 12:45
Slide decks of JSConf 2014
@nikcorg
nikcorg / tabkill.sh
Created June 14, 2014 22:22
Kill all Chrome tabs (except apps)
tabkill () {
ps ux | \
grep '[C]hrome Helper --type=renderer' | \
grep -vi "Canary" | \
grep -v extension-process | \
tr -s ' ' | \
cut -d ' ' -f2 | \
xargs kill
}
React.createBackboneComponent = function (spec, compname) {
return React.createClass(_.extend({
// Assistants
serializeState: function () {
this.replaceState(this.serialize());
},
getModel: function () {
return this.props.model;
},
el: function () {
@nikcorg
nikcorg / spotify-lookup.js
Last active January 3, 2016 03:29
Radio Helsingin soittolistan sisällön kysely Spotifysta
var u = require("underscore");
var q = require("q");
var cheerio = require("cheerio");
var hyperquest = require("hyperquest");
var concat = require("concat-stream");
function trim(str) {
return str.trim();
}
@nikcorg
nikcorg / bower.json
Last active January 3, 2016 02:39
Localised Moment.js
{
"name": "moment-demo",
"version": "0.0.0",
"authors": [
"Niklas Lindgren <niklas@sc5.io>"
],
"description": "localisation inclusion demo",
"dependencies": {
"moment": "~2.5.0",
"requirejs": "~2.1.10"