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 / 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

module['exports'] = function chat (hook) {
var TelegramBot = require('node-telegram-bot-api');
var token = hook.env['TG_TOKEN'];
// Setup polling way
var bot = new TelegramBot(token);
bot.setWebHook('https://hook.io/k4ml/infomy')
// Matches /echo [whatever]
bot.onText(/\/echo (.+)/, function (msg, match) {
@k4ml
k4ml / python-type-error.md
Last active May 19, 2016 05:25
Python - TypeError: ‘str’ object is not callable

Python - TypeError: ‘str’ object is not callable

One common error faced by new python developer. The error message is a bit obscure if you don’t have fully grasp of the language — like what ‘callable’ is.

This error happen when you have code such as:-

print("Hello %s, your name is %s" (name, yourname))
@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 / tg-channel.py
Last active November 2, 2015 12:25
Sending message to channel
#!/usr/bin/env python
# encoding: utf-8
__author__ = 'kamal@belajar.github.io'
import sys
import telegram
def main(token, message):
bot = telegram.Bot(token) # Telegram Bot Authorization Token
@k4ml
k4ml / tgbot-ws.lua
Created July 15, 2015 04:38
telegram-bot webscript.io
local tg_token = 'your token'
if request.query['admin_command'] == 'setURL' and request.query['pass'] == 'xxx' then
local response = http.request {
url = 'https://api.telegram.org/bot' .. tg_token .. '/setWebhook',
params = {
url='https://demo-xxxx.webscript.io/script'
},
method='post',
}
@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 / 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)
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 / 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
*/