Skip to content

Instantly share code, notes, and snippets.

View xintron's full-sized avatar

Marcus Carlsson xintron

View GitHub Profile
@xintron
xintron / testrunner.py
Created April 19, 2010 21:56
Django testrunner for mongoengine
from django.test.simple import DjangoTestSuiteRunner
from django.test import TransactionTestCase
from mongoengine import connect
class TestRunner(DjangoTestSuiteRunner):
def setup_databases(self, **kwangs):
db_name = 'testsuite'
connect(db_name)
print 'Creating test-database: ' + db_name
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
import logging
from mpd import MPDClient, CommandError
from tornado.httpserver import HTTPServer
from tornado.ioloop import IOLoop
from tornado.web import Application
from tornado.websocket import WebSocketHandler
import unittest
from flask.ext.script import Manager, Server
from project import app, db
manager = Manager(app)
class Serve(Server):
def handle(self, *args, **kwargs):
<?php
$url = 'http://www.trafiken.nu/TrafikenServices/TraveltimeService.ashx?method=getTraveltime&region=VST&sectionId=3001';
$c = curl_init($url);
$options = array(
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => array('Content-type: application/json')
);
curl_setopt_array($c, $options);
$data = curl_exec($c);
<?php
$data = array();
$time = array();
for ($i = 97; $i < 173; $i++)
$data[chr($i)] = $i;
$s = microtime(true);
for ($i = 0; $i < 1000000; $i++) {
isset($data['g']);
location /code/ {
try_files $uri $uri/index.html =404;
}
location ~ /code/(?<uri_path>.*/)(?<page>\d+)$ {
try_files $uri $uri_path/index$page.html =404;
}
location ~ /foo/.*.html {
return 404;
#!/usr/bin/env python3
# encoding: utf-8
import os
import sys
import argparse
def parse_arguments():
parser = argparse.ArgumentParser()
parser.add_argument('file')
<?php
class Foo {
public function __construct() {
var_dump(get_object_vars($this));
}
}
class Bar {
public function __construct(Array $args) {
foreach ($args as $key => $value) {
#!/bin/bash
# Original: http://frexx.de/xterm-256-notes/
# http://frexx.de/xterm-256-notes/data/colortable16.sh
# Modified by Aaron Griffin
# and further by Kazuo Teramoto
FGNAMES=(' black ' ' red ' ' green ' ' yellow' ' blue ' 'magenta' ' cyan ' ' white ')
BGNAMES=('DFT' 'BLK' 'RED' 'GRN' 'YEL' 'BLU' 'MAG' 'CYN' 'WHT')
echo " ┌──────────────────────────────────────────────────────────────────────────┐"
@xintron
xintron / loop.php
Created August 16, 2013 10:42
Example showing how inefficient foreach + range are together (thanks to PHP returning the full array instead of doing it like e.g. python which is yielding the current number when looping over a range). Setting range to 1000000 will exhaust 128MB memory in PHP while the for loop has no such limit.
<?php
$s = microtime(true);
$c = 0;
foreach(range(1, 100000) as $i) {
$c++;
}
$e = microtime(true);
printf("Foreach :: Time: %f, count: %d\n", $e-$s, $c);
$s = microtime(true);