Skip to content

Instantly share code, notes, and snippets.

@mgax
mgax / httpd.rb
Created January 19, 2012 21:20
Toy http server in ruby
require 'socket'
httpd = TCPServer.open('0.0.0.0', 6000)
loop {
client = httpd.accept
while line = client.gets
puts line
if line.chomp.length == 0
client.puts "200 OK\n\nhello client!\n"
break
@mgax
mgax / manage.py
Created January 20, 2012 19:22
Flask application template
#!/usr/bin/env python
import flask
import flaskext.script
default_config = {
}
def create_app():
import views
--- schema.py.orig 2012-01-22 18:02:07.000000000 +0200
+++ schema.py 2012-01-22 18:02:08.000000000 +0200
@@ -2018,6 +2018,8 @@
are mutually dependent on each other.
"""
+ if isinstance(name, int):
+ name = str(name)
super(ForeignKeyConstraint, self).\
__init__(name, deferrable, initially)
@mgax
mgax / fix_configure.diff
Created February 15, 2012 21:34
Patch by ecarreras to fix bup `configure` script
commit 218d382cf3b09ad146f5cd49df83e29c0d40657e
Author: Eduard Carreras <[email protected]>
Date: Fri Nov 11 11:23:12 2011 +0100
FIX Using prefix from configure parameter
diff --git a/Makefile b/Makefile
index ce91ff0..ecb0604 100644
--- a/Makefile
+++ b/Makefile
@mgax
mgax / consume.py
Created February 17, 2012 09:26
WeeChat notifications
# consume notifications from redis
import sys
import json
import subprocess
import redis
def growl(message):
args = ['growlnotify', '-m', message]
@mgax
mgax / thread_job.py
Created February 17, 2012 15:40
Run a job in a separate thread, with access to ZODB
import threading
import logging
import transaction
log = logging.getLogger(__now__)
def launch_job(context, callback):
"""
Launch a job in a separate thread::
@mgax
mgax / httpd.rb
Created February 26, 2012 11:05
require 'socket'
httpd = TCPServer.open('0.0.0.0', 6000)
loop {
client = httpd.accept
client.puts "HTTP/1.0 200 OK\n"
client.puts ""
client.puts "Hello world!"
$ invproj +proj=sterea +lat_0=46 +lon_0=25 +k=0.99975 +x_0=500000 +y_0=500000 +ellps=krass +units=m +no_defs -f "%.6f"
780332.071 412352.520
780361.183 412349.803
780414.748 412316.034
780514.385 412336.218
780549.049 412350.579
780582.818 412346.698
780575.055 412295.073
780463.655 412278.771
780462.897 412264.797
@mgax
mgax / gist:2029356
Created March 13, 2012 15:14
Migrat un portal la CHM3(-BE)

Pași pentru migrat o instanță la CHM3-BE:

  1. Presupunem că există o instanță fresh de CHM(-BE) numită chm3
  2. Copiat site (zexp sau copy/paste)
  3. Editat bundle, pus la "CHM3-BE"
  1. Dacă site-ul avea bundle propriu:
@mgax
mgax / apache_log.py
Created March 28, 2012 13:42
Count Apache log entries
# parse custom log format, which includes request duration and virtualhost name
from __future__ import division
from collections import namedtuple
import re
from dateutil.parser import parse as parse_date
LogEntry = namedtuple('LogEntry', 'datetime duration method url vhost '
'status size referrer useragent client')