Skip to content

Instantly share code, notes, and snippets.

View ptte's full-sized avatar

Patrik Ring ptte

View GitHub Profile

Keybase proof

I hereby claim:

  • I am ptte on github.
  • I am ptte (https://keybase.io/ptte) on keybase.
  • I have a public key ASBeAao5TOV4fFTZwxcOtCTOiCJ8s5i52pMr1vfHRm_XXQo

To claim this, I am signing this object:

<?php
date_default_timezone_set('UTC');
function rampupAlgo($x, $start) {
return floor(pow(1.47 * $x, 4) + ($x * $start));
}
function rampupExponential($start_time, $end_time, $min, $max, $now) {
$diff = $max - $min;
$start_unix = strtotime($start_time);
@ptte
ptte / callback_scoping.js
Created April 7, 2014 21:25
A somewhat non obvious scoping issue of javascripts callbacks
function test() {
for (var i=0;i < 5;i++) {
console.log('orig: '+ i);
// Crazy function with a callback here, making it async
setTimeout(function () {
// We might expect `i` to be whatever it was in the loop
// when we called the setTimeout, but it's actually not evaluated
// until the "callback" runs, and hence it will have the value
// `i` had in that exact moment.
@ptte
ptte / php_gc.php
Created April 7, 2014 21:24
PHP garbage collection example, shows how random phps gc is sometimes
This file has been truncated, but you can view the full file.
<?php
$do = 1000;
$done = 0;
while ($done < $do) {
$done++;
$batch = [
['user_id' => 234234534, 'email' => 'dndsfhbdshfbdshfbhdsfbghjfsbghbfs'],
['user_id' => 234234534, 'email' => 'dndsfhbdshfbdshfbhdsfbghjfsbghbfs'],
<?php
$list = [1,2,3,4,5];
foreach ($list as &$item) {}
foreach ($list as $item) {}
// would be 1,2,3,4,5 right?
var_dump($list);
@ptte
ptte / auth.js
Last active December 29, 2015 02:49
Custom authentication example for node hapi library Just an example of simplest possible custom authentication to build on. The slightly limited documentation is available here: http://spumko.github.io/resource/api/#server-auth-name--options-
// Hapi Custom auth
// ===========
//
// ## /lib/auth.js
//
var internals = {};
var Hapi = require('hapi');
exports = module.exports = internals.Scheme = function (server, options) {};