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 / index.html
Created October 31, 2014 21:19
SIPJS demo
<html>
<head>
<script src="http://sipjs.com/download/sip-0.6.2.min.js"></script>
<script>
</script>
</head>
<body>
<input id="phoneNumber"></>
<button id="startCall">Call</button>
<button id="endCall">End</button>
@k4ml
k4ml / sse.py
Last active August 29, 2015 14:09
Tailf to browser through Server Sent Events (SSE)
"""
Tail file to browser using Server Sent Events (SSE) + gevent.
Based on http://the.taoofmac.com/space/blog/2014/11/16/1940#python-patterns--take-two
Twisted+websocket implementation - https://github.com/k4ml/websocket_stdout_example
Requirements:-
sudo pip install bottle
@k4ml
k4ml / test-in-php.md
Last active August 29, 2015 14:14
Testing in PHP

Let say I have this code:-

<?php
namespace myapp/postracker;

use Guzzle\Http\Client;

class Parcel {
 public function __construct($parcelNo) {
@k4ml
k4ml / simple-widget.php
Last active August 29, 2015 14:16
Display JSON as widget
<?php
/*
Plugin Name: My Widget
Plugin URI: http://mydomain.com
Description: My first widget
Author: Me
Version: 1.0
Author URI: http://mydomain.com
Original Source: https://github.com/pommiegranit/wp-widgets/blob/master/mywidget-basic.php
*/
import requests
base_url = 'https://gst.customs.gov.my/TAP'
s = requests.session()
# STEP 1
response = s.get('%s/GetWlbToken' % base_url)
print response.headers
token = response.headers['fast-ver-last']
@k4ml
k4ml / models.py
Created June 26, 2015 00:42
Telegram Bot models
from peewee import *
db = SqliteDatabase(None)
class BaseModel(Model):
class Meta:
database = db
class TGUser(BaseModel):
id_ = IntegerField(primary_key=True)
<div class="frm-item" jsselect="$this">
<label jscontent="$this"></label><br />
<input type="text" jsvalues="value:$item[$this]"><br />
</div>
<script>
jq("a.item-result").live('click', function() {
var itemid = jq(this).attr('itemid');
var baseurl = 'proxy.php?url=http://localhost:9999/item';
jq.getJSON(baseurl + '/' + itemid, function(json) {
@k4ml
k4ml / QBuilder.class.php
Created November 11, 2010 22:06
Generic SQL query builder
<?php
class QBuilderCondition {
protected $conjunction = 'AND';
protected $wheres = array();
public function __construct($conjunction = 'AND') {
$this->conjunction = $conjunction;
}
<?php
function modulename_theme($existing, $type, $theme, $path) {
return array(
'formtemplate_horizontal' => array(
'arguments' => array('form' => NULL),
),
);
}
function theme_formtemplate_horizontal($form) {
#!/usr/bin/env python
from optparse import OptionParser
from os.path import join, dirname, abspath
from string import Template
import os, sys
parser = OptionParser()
parser.add_option("-a", "--address", default="127.0.0.1", help="Server address to listen")