Skip to content

Instantly share code, notes, and snippets.

@nikcorg
nikcorg / gist:4161502
Last active October 13, 2015 07:37
Slo-mo transitions styles
document.querySelector("head")
.appendChild(document.createElement("style"))
.innerText =
"* {" +
["transition-property: all !important","transition-duration: 2s !important"]
.map(function (s) {
return ["-webkit-","-moz-","-ms-","-o-", ""]
.map(function (p) { return p + s; });
})
.reduce(function (flat, arr) {
(function ($) {
var keys = {
ARR_RIGHT: 39,
ARR_LEFT: 37,
SPACE: 32
};
var btnNext = $("input#next");
var btnPrev = $("input#prev");
function kbdCntrl(e) {
@nikcorg
nikcorg / index.html
Last active January 14, 2017 17:09
Shakespearean insult generator
<html>
<head>
<meta charset="utf-8">
<title>Shakespearean insult generator</title>
<style>
* {
box-sizing: border-box;
font-family: "Comic Sans MS", "Comic Sans";
}
body {
@nikcorg
nikcorg / quick-install.sh
Created December 12, 2012 17:41
Drupal up and running in 60 seconds
#!/bin/bash
CWD=$(pwd)
ROOT="$CWD/drupal-$(date +%F-%H%M%S)"
DRUPAL="http://ftp.drupal.org/files/projects/drupal-7.17.tar.gz"
MODULES="entity restws devel :devel_generate ctools services :xmlrpc_server"
CMDS="drush curl patch"
LOG="$CWD/install.log"
exec 2>$LOG
@nikcorg
nikcorg / index.html
Created December 18, 2012 13:44
Experimenting with partially redrawing canvas
<!doctype html>
<html>
<head>
<title>Canvas with partial redraw</title>
</head>
<body>
<script type="text/javascript">
function prop(pname) {
return function (o) {
@nikcorg
nikcorg / hierarchical.js
Created December 19, 2012 10:32
Experimenting with prototype inheritance
var Foo = (function (Parent) {
var _super = Parent.prototype;
function Foo() {
Parent.call(this);
}
Foo.prototype = new Parent;
Foo.prototype.constructor = Foo;
Foo.prototype.ping = function () {
@nikcorg
nikcorg / jump-to-project.bash
Created December 20, 2012 11:58
Shell assistant for navigating between project dirs
#!bash
# Usage:
#
# In your .bashrc
#
# export PROJECTS_HOME=<path_to_projects_root>
# source jump-to-project.bash
#
# In you shell:
@nikcorg
nikcorg / a-umd-stub.js
Last active December 10, 2015 13:58
UMD signature stub. Relies on map (possibly required stub included) for not repeating the dependencies list.
(function (root, factory) {
var name = "FooMod";
var deps = ["this", "that", "whatnot"];
if (typeof exports === "object") {
module.exports = factory.apply(undefined, deps.map(function (d) { return require(d); }));
} else if (typeof define === "function" && define.amd) {
define(deps, factory);
} else {
root[name] = factory.apply(undefined, map(deps, function (d) { return root[d]; }));
@nikcorg
nikcorg / devserver.sh
Last active December 13, 2015 23:49
Grunt task for sending SIGHUP to processes and a shell script to go with it. Combined with a watch process, run a dev-server which refreshes on changes in the codebase.
#!/bin/bash
PIDFILE="/tmp/runserver.pid"
CWD=$(pwd)
RUNENV=$1
SERVER_PID=""
CRASH_RECOVERIES=0
CRASH_RECOVERIES_MAX=3
start_server() {
@nikcorg
nikcorg / fbclient.js
Last active December 14, 2015 00:09
The produce of a HelsinkiJS mini-workshop. Pulls in the profile images of members of the HelsinkiJS group and renders them as a webpage.
// Import the required modules
var fs = require("fs");
var parseUrl = require("url").parse;
var http = require("http");
var express = require("express");
var handlebars = require("handlebars");
var Q = require("q");
var FB = require('fb');
// Read the template file from disk