Skip to content

Instantly share code, notes, and snippets.

View thejhh's full-sized avatar
💭
Excellence isn't believing you're best; It's about always striving to get better

Jaakko Heusala thejhh

💭
Excellence isn't believing you're best; It's about always striving to get better
View GitHub Profile
@thejhh
thejhh / gist:edbd00b6c8a4f60460db
Last active August 29, 2015 14:11
Building remote version of local JavaScript [hidden] "class"
var Socket = require('src/backend/io/Socket.js');
/** RemoteSocket */
function RemoteSocket(socket) {
debug.assert(socket).is('object');
debug.assert(socket.$id).is('uuid');
debug.assert(socket.worker).is('string');
debug.assert(socket.id).is('string');
function is_object(a) {
return a && (typeof a === 'object');
}
function step(last, current) {
if(is_object(last)) {
return last[current];
}
}
"use strict";
var y = [] + {};
console.log( typeof y );
var x = {} + [];
console.log( typeof x );
// $ node foo.js
// string
@thejhh
thejhh / gist:8145497
Created December 27, 2013 10:56
Proof of concept of function-based promise (wrapper) implementation
// The (wrapper) implementation of function based promise
var Q = require('q');
var foo = {};
foo.sum = function(a, b) {
function wrap_p(p) {
function f() {
var args = Array.prototype.slice.call(arguments);
/* My Solution for http://reaktor.fi/ura/fast_track/ */
function test(input) {
return Math.max.apply(Math, input.split('').map(function(d, i, a) {
return (i+5 <= a.length) ? a.slice(i, i+5).reduce(function(p, c) { return p*c; }) : 0;
}));
}
// Test it
var util = require('util');
mysql> START TRANSACTION;
Query OK, 0 rows affected (0.00 sec)
mysql> SET @ids := '';
Query OK, 0 rows affected (0.00 sec)
mysql> DELETE FROM `item` WHERE (`id` = 4) AND (SELECT @ids := CONCAT_WS(',', @ids, id)) LIMIT 1;
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> SHOW WARNINGS;

Here is the error without Q's long stack trace support:

 1) fs fs.fchown(fd) can change tmp/test1.txt to own uid, gid:
 TypeError: path must be a string
  at fs.chown (fs.js:853:11)
  at Promise.apply (/home/jhh/git/nor-fs/node_modules/q/q.js:1022:26)
  at Promise.promise.promiseDispatch (/home/jhh/git/nor-fs/node_modules/q/q.js:661:41)
  at /home/jhh/git/nor-fs/node_modules/q/q.js:1273:25
  at flush (/home/jhh/git/nor-fs/node_modules/q/q.js:106:17)

at process._tickCallback (node.js:415:13)

@thejhh
thejhh / app.html
Last active December 19, 2015 01:29
Example code for our new UI library
<!DOCTYPE HTML>
<html>
<head>
<title>Example Form Application</title>
</head>
<body>
<h1>Example Form Application</h1>
<div class="form" data-action="resource.php"></div>
if [ "$(id -u)" != "0" ]; then
echo "This script must be run as root" 1>&2
exit 1
fi
@thejhh
thejhh / gist:4701550
Created February 3, 2013 12:14
Script that creates google calendar events for turn changes in LT31 online Freeciv game.
#!/bin/sh
game="LT31"
start_turn=66
start_time=1359900000
end_turn=200
hours=23
for((i=$start_turn; i<=$end_turn; i++)); do
turn="$i"