Skip to content

Instantly share code, notes, and snippets.

@jsmarkus
jsmarkus / gist:1280471
Created October 12, 2011 06:49
if express was in PHP
<?php
//define simple route
$app->get('/', function ($req, $res, $next) {
$res->render('main.tpl', array('title'=>'Hello world'));
});
//mount class
$app->mount('MyController', '/myctrl');
@jsmarkus
jsmarkus / case1.js
Created December 21, 2011 13:12
Javascript function-in-function performance
var a = function (v) {
function b (v) {
return 42;
}
return b(v);
}
var start = (new Date).getTime();
for (var i=0; i < 1e6; i++) {
mark@in137:~$ cd tmp
mark@in137:~/tmp$ mkdir express-test
mark@in137:~/tmp$ cd express-test
mark@in137:~/tmp/express-test$ express
create : .
create : ./package.json
create : ./app.js
create : ./public
create : ./routes
mrak@nixbox:~/GIT/visionmedia/superagent$ make test
................................................................
✖ 18 of 64 tests failed:
1) request with an object should format the url:
TypeError: object is not a function
at Object.CALL_NON_FUNCTION (native)
at Request.callback (/home/mrak/GIT/visionmedia/superagent/test/node/basic.js:46:9)
#!/bin/sh
FILES=`git status --porcelain | grep -P '^[\sAM]+' | sed 's/\(^\s*[AM]\+\)\s\+//'`
G="grep -n -H --color=auto -P"
RED=`echo -e '\033[41m\033[37m'`
NORMAL=`echo -e '\033[0m'`
for file in `echo $FILES | sort -u`
do
$G console $file
$G var_dump $file
@jsmarkus
jsmarkus / about.js
Created May 31, 2012 13:46
Ghost website
function about() {
/*
Subject: Сайт-призрак
Date: 2012-06-01
Этот сайт сделан для прикола.
*/
}
@jsmarkus
jsmarkus / gist:3340123
Created August 13, 2012 12:20
Command line YQL google searcher on FSM pattern. Test of npm module "automata".
var automata = require('automata')
, yql = require('yql')
, readline = require('readline')
;
automata.registerFSM({
name : "Test",
logic : TestLogic,
state : [
{ name : 'idle', onEnter : 'idle', initial : true },
public function getDistanceTo(Geometry_Point $anotherPoint)
{
//TODO!!!!
if($this->getProjection() !== $anotherPoint->getProjection())
{
throw new Geometry_Exception('Projection mismatch');
}
$lat1 = $this->getLat();
<?php
// Construct an HTTP POST request
$clientlogin_url = "https://www.google.com/accounts/ClientLogin";
$clientlogin_post = array(
"accountType" => "HOSTED_OR_GOOGLE",
"Email" => "*********************************************",
"Passwd" => "*********************************************",
"service" => "writely",
"source" => "my-fake-app"
<?php
class GReader {
protected $auth;
public function __construct($login, $password) {
$clientlogin_url = "https://www.google.com/accounts/ClientLogin";
$clientlogin_post = array(
"accountType" => "HOSTED_OR_GOOGLE",