Skip to content

Instantly share code, notes, and snippets.

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

Kamal Mustafa k4ml

🏠
Working from home
View GitHub Profile
@k4ml
k4ml / log.txt
Created June 10, 2014 07:59
Log
64.242.88.10 - - [07/Mar/2004:16:05:49 -0800] "GET /twiki/bin/edit/Main/Double_bounce_sender?topicparent=Main.ConfigurationVariables HTTP/1.1" 401 12846
64.242.88.10 - - [07/Mar/2004:16:06:51 -0800] "GET /twiki/bin/rdiff/TWiki/NewUserTemplate?rev1=1.3&rev2=1.2 HTTP/1.1" 200 4523
64.242.88.10 - - [07/Mar/2004:16:10:02 -0800] "GET /mailman/listinfo/hsdivision HTTP/1.1" 200 6291
64.242.88.10 - - [07/Mar/2004:16:11:58 -0800] "GET /twiki/bin/view/TWiki/WikiSyntax HTTP/1.1" 200 7352
64.242.88.10 - - [07/Mar/2004:16:20:55 -0800] "GET /twiki/bin/view/Main/DCCAndPostFix HTTP/1.1" 200 5253
64.242.88.10 - - [07/Mar/2004:16:23:12 -0800] "GET /twiki/bin/oops/TWiki/AppendixFileSystem?template=oopsmore¶m1=1.12¶m2=1.12 HTTP/1.1" 200 11382
64.242.88.10 - - [07/Mar/2004:16:24:16 -0800] "GET /twiki/bin/view/Main/PeterThoeny HTTP/1.1" 200 4924
64.242.88.10 - - [07/Mar/2004:16:29:16 -0800] "GET /twiki/bin/edit/Main/Header_checks?topicparent=Main.ConfigurationVariables HTTP/1.1" 401 12851
64.242.88.10 - - [07/Mar/2004:16:30:29 -08
@k4ml
k4ml / int.txt
Last active August 29, 2015 14:02
Interview
$foo = "Hello";
function alert_a() {
global $foo;
$bar = " World";
echo ($foo . $bar);
}
@k4ml
k4ml / cutv.sh
Created April 17, 2014 05:42
Cut video using avconv
# cut video at minute 00:00:40 for 4 second.
avconv -i video.mp4 -vcodec copy -acodec copy -ss 00:00:40 -t 00:00:04 output.mp4
@k4ml
k4ml / spam.html
Created April 2, 2014 09:02
Just a spammy page some guy shared on FB
<!DOCTYPE html>
<html>
<head><script type="text/javascript">var NREUMQ=NREUMQ||[];NREUMQ.push(["mark","firstbyte",new Date().getTime()]);</script>
<title>How good are Malaysian artists? See it for yourself.</title>
<meta name="title" content="How good are Malaysian artists? See it for yourself."/>
<meta name="description" content="Check out Prudential Malaysian Eye, a contemporary art exhibition featuring Malaysian artists from now to the end of April."/>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta property="og:title" content="How good are Malaysian artists? See it for yourself." />
<meta property="og:description" content="Check out Prudential Malaysian Eye, a contemporary art exhibition featuring Malaysian artists from now to the end of April." />
@k4ml
k4ml / messaging.py
Created January 29, 2014 23:26
POPO - Plain Old Python Object
class Messaging(object):
def __init__(self, user, sender, receiver, message):
self.user = user
self.sender = sender
self.receiver = receiver
self.message = message
def send(self):
required_points = self.get_required_points()
if required_points > self.user.points:
@k4ml
k4ml / base.html
Created December 5, 2013 03:53
Sekizai example
{% load sekizai_tags %}
<doctype html>
<html>
<head>
{% block css %}{% endblock %}
{% render_block "css" %}
</head>
<body>
{% block content %}
{% endblock %}
@k4ml
k4ml / numbered_canvas.py
Created October 19, 2013 20:21
Implement 'page x of y' feature for reportlab pdf generation library. This is slight modification to the original snippet which use a placeholder instead of drawing the string containing the total pages number directly. Original snippet - http://stackoverflow.com/a/1088029
from reportlab.pdfgen.canvas import Canvas
class NumberedCanvas(Canvas):
def __init__(self, *args, **kwargs):
Canvas.__init__(self, *args, **kwargs)
self._saved_page_states = []
def showPage(self):
self._saved_page_states.append(dict(self.__dict__))
self._startPage()
@k4ml
k4ml / supervisord.sh
Created October 5, 2013 22:28
Script to control supervisord daemon. This is taken from somewhere but forgot already the original source.
#!/bin/bash
NAME=supervisord
SUPERVISORD=/usr/bin/supervisord
SUPERVISORCTL=/usr/bin/supervisorctl
PIDFILE=$HOME/var/run/supervisord.pid
OPTS="-c $HOME/etc/supervisord.conf"
PS=$NAME
TRUE=1
FALSE=0
@k4ml
k4ml / variadic.py
Created September 4, 2013 17:12
Example use case of variadic function - function with arbitrary arguments.
class Database(object):
def save(self, using=default_db, force=False):
pass
# override
class MyDatabase(Database):
def save(self, custom_flag=1, *args, **kwargs):
# use custom_flag
if custom_flag:
pass
@k4ml
k4ml / php-dev.sh
Last active December 20, 2015 17:09
PHP dev server using bash and nc
#!/bin/bash
read -r line
read -r REQUEST_METHOD REQUEST_URI REQUEST_HTTP_VERSION <<< "$line"
# parse url such as http://localhost:9000/?name=kamal
GET=$(echo "$REQUEST_URI" | sed 's/^\/?//g' | sed 's/&/ /g')
# pass to php for actual processing
output=$(php5-cgi -f index.php "$GET")