Skip to content

Instantly share code, notes, and snippets.

@meyt
meyt / main.py
Last active February 10, 2019 14:39
Simple stupid file uploader with python3.6 and nanohttp>=1.10.4
from os import makedirs
from os.path import join, basename
from sys import argv
from nanohttp import (
RestController,
Static,
html,
context,
quickstart,
@meyt
meyt / post-commit.sh
Created March 6, 2019 17:54
Git auto-tag hook by package.json (nodejs packages)
#! /bin/bash
# File: .git/hooks/post-commit
# source: https://coderwall.com/p/mk18zq/automatic-git-version-tagging-for-npm-modules
version=`git diff HEAD^..HEAD -- "$(git rev-parse --show-toplevel)"/package.json | grep '^\+.*version' | sed -s 's/[^0-9\.]//g'`
if [ "$version" != "" ]; then
git tag -a "v$version" -m "`git log -1 --format=%s`"
echo "Created a new tag, v$version"
fi
@meyt
meyt / nuxt-router-hack-plugin.js
Created March 14, 2019 07:00
Force refresh current route on vue-router
/*
Problem: When user click on a link that refers to current path,
nothing happen. in vue-router logic, same path must ignore.
Expected: As browsers UX on old-fashion websites, user expects
something happen when click on a link, like refresh the current
route.
Solution: We hack the vue-router push method
(thanks to vue-router clean code) to append a query-string
@meyt
meyt / numberingSystems.js
Created May 1, 2019 05:22
Numbering systems in JS
const numberingSystems = {
arab: '٠١٢٣٤٥٦٧٨٩',
arabext: '۰۱۲۳۴۵۶۷۸۹',
bali: '᭐᭑᭒᭓᭔᭕᭖᭗᭘᭙',
beng: '০১২৩৪৫৬৭৮৯',
deva: '०१२३४५६७८९',
fullwide: '0123456789',
gujr: '૦૧૨૩૪૫૬૭૮૯',
guru: '੦੧੨੩੪੫੬੭੮੯',
hanidec: '〇一二三四五六七八九',
@meyt
meyt / setup-postgres.sh
Last active May 9, 2019 17:41
Quick setup and configure postgres9.x on Ubuntu (development)
# How to run?
# sudo bash ./setup-postgres.sh
# Install
apt install -y postgresql;
# Set default password "postgres" for postgres user
sudo -u postgres psql -c "ALTER USER postgres WITH PASSWORD 'postgres';";
# Allow all type of connection with md5 authentication
@meyt
meyt / dictme.sh
Created May 27, 2019 10:01
Goldendict + TTS + Global shortkey for selected text on linux (ubuntu)
#!/bin/bash
# This script grabs selected text from X11, open it with goldendict
# and starts to speech
# You can configure a global shortkey through your desktop:
# on XFCE: Keyboard settings > Application Shortcuts
# add new one with command: bash /full/path/of/the/dictme.sh
###
# Grab selected text from X11
@meyt
meyt / purge-restore.sh
Last active July 24, 2019 06:28
Resotre latest purged APT packages
#!/bin/bash
# from: https://serverfault.com/a/646116
sudo apt-get install `grep Purge /var/log/apt/history.log | tail -1 | sed -e 's|Purge: ||g' -e 's|([^)]*)||g' -e 's|:[^ ]* ||g' -e 's|,||g'`
@meyt
meyt / work.sh
Last active October 10, 2019 00:01
Personal workspace switcher
#! /bin/bash
#
# Personal workspace switcher
# author: meyt
#
# - Change directory to project path
# - Automatic python virtualenv activate/deactivate
# - Auto-complete
#
# Install
@meyt
meyt / v-text-field.vue
Created March 18, 2020 21:19
nativescript-vue material text field
<template>
<StackLayout :class="classess">
<FlexboxLayout
flexDirection="row"
:justifyContent="hintIsRtl ? 'flex-end' : 'flex-start'"
class="field-label"
>
<StackLayout
v-if="value_.length > 0"
class="wrapper"
@meyt
meyt / nativescript-fullscreen.js
Last active April 3, 2020 15:36
Enable fullscreen view on android
import * as app from 'tns-core-modules/application'
import { device } from 'tns-core-modules/platform'
export function hideSystemUi () {
if (!app.android || parseInt(device.sdkVersion) < 21) { return }
const androidViewPkg = android.view // eslint-disable-line no-undef
const View = androidViewPkg.View
const window = app.android.startActivity.getWindow()
const decorView = window.getDecorView()
decorView.setSystemUiVisibility(