Skip to content

Instantly share code, notes, and snippets.

View phizaz's full-sized avatar
😀

Konpat phizaz

😀
View GitHub Profile
@phizaz
phizaz / plot.py
Last active February 22, 2017 10:04
Matplotlib: plotting with x-ticks labels
def plot(keys: list, vals: list):
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.add_subplot(111)
x = range(len(vals))
ax.set_xticks(x) # plot every tick
ax.set_xticklabels(keys, rotation=90)
ax.plot(x, vals)
fig.savefig('output.png', bbox_inches='tight') # bbox_inches='tight' to prevent text-overflow out of the frame
@phizaz
phizaz / pip-register.sh
Created February 15, 2017 17:03
Python's Pip Scripts
# register to pip
python setup.py register -r pypi
@phizaz
phizaz / run.cmd
Created February 9, 2017 16:53
Batch script that escapes %cd% and %home% by using ${cd} and ${home} instead
@echo off
REM run command by parsing ${cd} to %cd% and ${home} to %home%
setlocal ENABLEDELAYEDEXPANSION
set str=%*
set str=!str:${cd}=%CD%!
set str=!str:${home}=%HOME%!
REM run the parsed command
%str%
@phizaz
phizaz / my.ahk
Last active February 24, 2017 14:25
My AutoHotKey (Dvorak + previous Mac User)
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
sendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
#MaxHotkeysPerInterval 200
; Capslock + jkli (left, down, up, right)
#InstallKeybdHook
#UseHook On
@phizaz
phizaz / async.py
Last active April 3, 2024 15:44
Python turn sync functions to async (and async to sync)
import functools
def force_async(fn):
'''
turns a sync function to async function using threads
'''
from concurrent.futures import ThreadPoolExecutor
import asyncio
pool = ThreadPoolExecutor()
@phizaz
phizaz / ctrl-alt.ahk
Last active January 23, 2017 18:45
Autohotkey: Swapping ctrl and alt but keeping the physical "alt+tab" functionality
; escaper (this is used to reset all the keys)
~lalt up::
{
send {ctrl up}
send {lctrl up}
send {alt up}
send {lalt up}
return
}
@phizaz
phizaz / all.js
Created January 19, 2017 11:40
Javascript Utils
/**
* returns true iff val equals every element in the list
*/
function all(list, val) {
if (list.length === 0) return false
const first = list[0]
if (first !== val) return false
for (const elem of list) {
if (first !== elem) return false
}
@phizaz
phizaz / autohotkey.ahk
Last active January 10, 2017 03:02
AutoHotkey Mapping for Former Mac Users on Windows
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
; Tab Switching
+![::
Send, ^+{TAB}
return
+!]::
@phizaz
phizaz / keybindings.json
Created January 6, 2017 16:25
VSCode Key Bindings for Windows using "ALT" as the main key
// Place your key bindings in this file to overwrite the defaults
[
{
"key": "alt+a",
"command": "editor.action.selectAll"
},
{
"key": "alt+x",
"command": "editor.action.clipboardCutAction"
},
@phizaz
phizaz / awaitboth.py
Last active December 20, 2016 03:48
Python awaitasync: wait both async and sync in one function
import asyncio
def unzip(l):
return zip(*l)
def merge(*itrs):
from itertools import chain
return chain.from_iterable(itrs)
async def wait(l):