Skip to content

Instantly share code, notes, and snippets.

View fikr4n's full-sized avatar

Fikrul Arif fikr4n

  • Telkom
  • Indonesia
View GitHub Profile
@fikr4n
fikr4n / totpauth.sh
Last active July 6, 2021 05:13
TOTP (like in Google Authenticator android app) using https://github.com/pyauth/pyotp, and (optional) gpg to secure the secret
#!/bin/bash
# How to use
# 1. Clone https://github.com/pyauth/pyotp.git
# 2. Put this file in the repo root dir
# 3. GPG-encrypt your TOTP key/seed (without newline), place it in secret.asc in the repo root dir
# 4. Run this file
cd `dirname $0`/src
watch gpg -dq ../secret.asc \| python3 -c \''import pyotp;print(pyotp.TOTP(input()).now(),end="")'\'
@fikr4n
fikr4n / colortoalpha.sh
Created February 28, 2019 06:06
Convert color to alpha with ImageMagick
convert input.jpg -fuzz 20% -transparent white output.png
# taken from http://www.piware.de/2011/01/creating-an-https-server-in-python/
# generate server.xml with the following command:
# openssl req -new -x509 -keyout server.pem -out server.pem -days 365 -nodes
# run as follows:
# python simple-https-server.py
# then in your browser, visit:
# https://localhost:4443
import BaseHTTPServer, SimpleHTTPServer
import ssl
@fikr4n
fikr4n / coroutine-pool.kts
Last active March 30, 2023 14:16
A quick example of thread pool-like Kotlin coroutine
import kotlinx.coroutines.experimental.*
import kotlinx.coroutines.experimental.channels.*
class FixedPool(val workerCount: Int) {
val channel = Channel<Task>()
val jobs = mutableListOf<Job>()
init {
start() // start immediately
@fikr4n
fikr4n / isupertarg.kts
Last active October 13, 2017 03:07
Indirect generic superclass actual type arguments of a Java class (with Kotlin)
#!/usr/bin/env kotlinc -script
import java.lang.reflect.*
import kotlin.reflect.*
fun targ(c: Class<*>) = c.typeParameters.toList()
fun satarg(c: Class<*>) = (c.genericSuperclass as? ParameterizedType)?.
actualTypeArguments?.toList() ?: emptyList()
fun isatarg(c: Class<*>?, ancestor: Class<*>, resolvedT: List<Type>): List<Type>? {
@fikr4n
fikr4n / typeface.py
Last active September 26, 2017 23:03
Translate string in basic latin script to mathematical symbols or add combining character as if the typeface/style is changed/applied
#!/usr/bin/env python3
# Raw table source: https://en.wikipedia.org/wiki/Mathematical_Alphanumeric_Symbols
table = (
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz',
'𝐀𝐁𝐂𝐃𝐄𝐅𝐆𝐇𝐈𝐉𝐊𝐋𝐌𝐍𝐎𝐏𝐐𝐑𝐒𝐓𝐔𝐕𝐖𝐗𝐘𝐙𝐚𝐛𝐜𝐝𝐞𝐟𝐠𝐡𝐢𝐣𝐤𝐥𝐦𝐧𝐨𝐩𝐪𝐫𝐬𝐭𝐮𝐯𝐰𝐱𝐲𝐳',
'𝐴𝐵𝐶𝐷𝐸𝐹𝐺𝐻𝐼𝐽𝐾𝐿𝑀𝑁𝑂𝑃𝑄𝑅𝑆𝑇𝑈𝑉𝑊𝑋𝑌𝑍𝑎𝑏𝑐𝑑𝑒𝑓𝑔ℎ𝑖𝑗𝑘𝑙𝑚𝑛𝑜𝑝𝑞𝑟𝑠𝑡𝑢𝑣𝑤𝑥𝑦𝑧',
'𝑨𝑩𝑪𝑫𝑬𝑭𝑮𝑯𝑰𝑱𝑲𝑳𝑴𝑵𝑶𝑷𝑸𝑹𝑺𝑻𝑼𝑽𝑾𝑿𝒀𝒁𝒂𝒃𝒄𝒅𝒆𝒇𝒈𝒉𝒊𝒋𝒌𝒍𝒎𝒏𝒐𝒑𝒒𝒓𝒔𝒕𝒖𝒗𝒘𝒙𝒚𝒛',
'𝖠𝖡𝖢𝖣𝖤𝖥𝖦𝖧𝖨𝖩𝖪𝖫𝖬𝖭𝖮𝖯𝖰𝖱𝖲𝖳𝖴𝖵𝖶𝖷𝖸𝖹𝖺𝖻𝖼𝖽𝖾𝖿𝗀𝗁𝗂𝗃𝗄𝗅𝗆𝗇𝗈𝗉𝗊𝗋𝗌𝗍𝗎𝗏𝗐𝗑𝗒𝗓',
'𝗔𝗕𝗖𝗗𝗘𝗙𝗚𝗛𝗜𝗝𝗞𝗟𝗠𝗡𝗢𝗣𝗤𝗥𝗦𝗧𝗨𝗩𝗪𝗫𝗬𝗭𝗮𝗯𝗰𝗱𝗲𝗳𝗴𝗵𝗶𝗷𝗸𝗹𝗺𝗻𝗼𝗽𝗾𝗿𝘀𝘁𝘂𝘃𝘄𝘅𝘆𝘇',
@fikr4n
fikr4n / pygigtk.py
Last active January 5, 2023 15:48
Interactive Python interpreter to play with GTK+ without blocking the console
#!/usr/bin/python3
"""An interactive Python interpreter to play with GTK+ without blocking the console
Usage:
./pygigtk.py
You don't need to call 'Gtk.main' in the console, just start using Gtk, such as
creating a window and 'show_all' it. Gtk, GObject, etc have been imported.
Author: fikr4n <github.com/fikr4n>
@fikr4n
fikr4n / tsignconv.py
Last active February 14, 2016 07:15
'Superkill' JVM type signatures to Java types converter
import re
p = re.compile(r'(\[*)([ZBCSIJFDV]|L([^;\s]+);)')
prims = {'Z': 'boolean', 'B': 'byte', 'C': 'char', 'S': 'short', 'I': 'int', 'J': 'long', 'F': 'float', 'D': 'double', 'V': 'void'}
def tr(s):
return [(i.group(3).replace('/', '.') if i.group(3) else prims[i.group(2)]) + ('[]' * len(i.group(1)))
for i in p.finditer(s)]
@fikr4n
fikr4n / usr_share_X11_xkb_rules_evdev.xml
Last active March 31, 2021 04:24
Arab Melayu / Jawi alphabet keyboard layout for X11/xkb
<!-- Modify /usr/share/X11/xkb/rules/evdev.xml by adding this in <layoutList> -->
<layoutList>
...
<layout>
<configItem>
<name>id</name>
<shortDescription>id</shortDescription>
<description>Indonesian (Arab Melayu, phonetic)</description>
<languageList>
<iso639Id>ind</iso639Id>
@fikr4n
fikr4n / int32.py
Created January 26, 2015 01:59
Convert Python integer to signed 32-bit equivalent
def int32(x):
x &= 0xffffffff # Convert to 32-bit
if bool(x & 0x80000000): # If negative
return x - 0x100000000
else:
return x