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 / bootstrap.py
Created November 3, 2017 12:12
Bootstrap python environment ready for use with buildout
import os
import sys
import subprocess
import functools
run = functools.partial(subprocess.call, shell=True)
run('virtualenv -p python3 .env')
run('.env/bin/pip install --upgrade setuptools')
@k4ml
k4ml / list.md
Created November 1, 2017 08:58
Nested list
  • list one
    • nested list
    • nested list 2
  • list two
@k4ml
k4ml / cherrypy-intro.md
Created March 5, 2017 08:06
Python web programming with cherrypy

This assuming you are on Linux or OSX machine. Make sure python version is 3.5 and above.

Create your project directory, let say we're building application named webby:-

mkdir webby
cd webbpy

Create new virtualenv that will be the PYTHON that we will use going forward in this project:-

@k4ml
k4ml / install-python.md
Created March 4, 2017 08:44
Installing Python from source

This is on Ubuntu 14.04, but should work in any Linux/OSX system:-

mkdir -p $HOME/python/3.6
wget https://www.python.org/ftp/python/3.6.0/Python-3.6.0.tgz
tar xzf Python-3.6.0.tgz
cd Python-3.6.0/
./configure --prefix=$HOME/python/3.6
make
make test
@k4ml
k4ml / keybase.io
Created February 11, 2017 02:08
keybase id proof
### Keybase proof
I hereby claim:
* I am k4ml on github.
* I am k4ml (https://keybase.io/k4ml) on keybase.
* I have a public key ASCZeLsQwrBVZescEQhSO6a9e0jJxvGbB0p9mw8_7epr_Ao
To claim this, I am signing this object:
@k4ml
k4ml / tgbot.py
Created June 27, 2015 22:49
Example telegram bot
import bottle
import requests
@bottle.route('/', method='POST')
def telegram_bot():
data = bottle.request.json
url = 'https://api.telegram.org/bot<YOUR_TOKEN>/sendMessage'
try:
@k4ml
k4ml / README
Last active December 10, 2016 22:33 — forked from rkusa/README
Install alpine linux on xhyve VM
# curl -LO http://wiki.alpinelinux.org/cgi-bin/dl.cgi/v3.3/releases/x86_64/alpine-3.3.3-x86_64.iso
curl -LO http://wiki.alpinelinux.org/cgi-bin/dl.cgi/v3.3/releases/x86/alpine-3.3.3-x86.iso
# create hdd image (8GB)
dd if=/dev/zero of=hdd.img bs=1g count=8
# extract kernel and initramfs
brew install cdrtools
isoinfo -i alpine-3.3.1-x86.iso -J -x /boot/initramfs-grsec > initramfs-grsec
isoinfo -i alpine-3.3.1-x86.iso -J -x /boot/vmlinuz-grsec > vmlinuz-grsec
@k4ml
k4ml / README.md
Last active November 9, 2016 00:31
Script to quickly send message using telegram bot

Bot request

This is how telegram send the request:-

POST / HTTP/1.1
Host: xxx.ngrok.io
Content-Type: application/json
Content-Length: 247
Accept-Encoding: gzip, deflate
X-Forwarded-Proto: https

X-Forwarded-For: 149.0.16.14

@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 / button.elm
Created October 29, 2016 23:16
Elm intro
import Html exposing (Html, button, div, text)
import Html.App as App
import Html.Events exposing (onClick)
main =
App.beginnerProgram { model = model, view = view, update = update }
-- MODEL