Skip to content

Instantly share code, notes, and snippets.

View luciferous's full-sized avatar
🏠
Working from home

Neuman Vong luciferous

🏠
Working from home
View GitHub Profile

PHP-WSGI

An example PHP-WSGI app:

<?php
require_once 'php-wsgi.php';
run_with_cgi(function($environ, $start_response) {
  try {
    $start_response('200 OK', array('Content-Type' => 'text/plain'));

return array("Hello World\n");

@luciferous
luciferous / README.md
Created April 27, 2010 07:18
WebSocket protocol for Diesel

WebSocket protocol for Diesel

Not tested, but a potential echo + timeout example:

from diesel import Application, Service, until_eol, sleep, bytes
from websocket import WebSocket
import time

def skip_one():

yield bytes(1)

#!/bin/sh
#RSS="http://www.reddit.com/r/Music/top/.rss?t=year"
RSS="http://www.reddit.com/r/listentothis/top/.rss?t=week"
YOUTUBE_RE="youtube\.com\/watch\?v=([^&\"]+)"
DATA=`curl --silent --compressed "$RSS"`
MATCHES=`echo $DATA | grep -Po "$YOUTUBE_RE"`
echo $DATA | hxselect -s '\n' -c item title | nl
for URL in $MATCHES;
do
cookiefile="/tmp/cookies-$( date +%s.%N ).txt"
@luciferous
luciferous / README
Created September 6, 2010 22:55
Sudoku solver in Ruby
A very simple Sudoku puzzle solver written in Ruby. This script is free every
way you look at it.
## Example usage
$ cat puzzle
15 2
7 8459
8 4795 6
5 6
@luciferous
luciferous / README.md
Created October 9, 2010 12:48
A very small HTTP Client with Rack/WSGI style interfaces

Tiny HTTP

A very small HTTP client with Rack/WSGI style interfaces.

The setup

$sid = 'ACxxxxxxxxxxxx';
$token = '12345678';
$http = new TinyHttp("https://$sid:$token@api.twilio.com");
@luciferous
luciferous / MockFunction.php
Created November 4, 2010 23:26
Mocks for Drupal functions
<?php
class MockFunction {
public $func;
public $returns;
private function __construct($func) {
$this->func = $func;
$this->returns = array();
}

Create a Subversion repository

Create the repository and import a test project.

$ svnadmin create svn
$ mkdir tmp
$ touch tmp/a tmp/b tmp/c
$ svn import tmp file://`pwd`/svn -m "initial commit"
@luciferous
luciferous / Twiml.php
Created March 5, 2011 00:52
Generates Twiml using SimpleXmlElement.
<?php
/**
* Copyright 2011 Neuman Vong. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
@luciferous
luciferous / README.md
Created May 6, 2011 08:19
Decorators for Javascript a la Python

Decorators for Javascript ala Python

Imagine a function named foo that takes two parameters, prints them to a console, and returns a boolean true if the two parameters are equal:

function foo(a, b) {
    console.log([a, b]);
    return a === b;
}
@luciferous
luciferous / echo.php
Created May 18, 2011 07:46
Various blocking and non-blocking IO demos
<?php
$ss = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
$iface = '0.0.0.0';
$port = 5432;
socket_set_option($ss, SOL_SOCKET, SO_REUSEADDR, 1);
socket_bind($ss, $iface, $port) or die("Could not bind\n");
socket_listen($ss, 1);