Skip to content

Instantly share code, notes, and snippets.

@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 / 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(
@meyt
meyt / simdver.sh
Created June 15, 2020 00:20
simdver
if $(cat /proc/cpuinfo | grep -q 'sse4'); then
simdver="sse4"
elif $(cat /proc/cpuinfo | grep -q 'sse3\|pni'); then
simdver="sse3"
else
simdver="sse2"
fi
@meyt
meyt / publickey-multiadd.sh
Created August 29, 2020 14:37
Add SSH public_key to all hosts in `~/.ssh/config`
#!/bin/bash
for host in `grep -P "^Host ([^*]+)$" $HOME/.ssh/config | sed 's/Host //'`; do
echo "copying to $host"
ssh-copy-id -f -i "$HOME/Downloads/id_rsa.pub" "$host"
done
@meyt
meyt / sasample.py
Created May 11, 2021 18:00
Strange behavior on SQLAlchemy
from sqlalchemy import MetaData, Column, Integer, String, ForeignKey
from sqlalchemy.orm import relationship, sessionmaker, scoped_session
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.engine import create_engine
engine = create_engine("sqlite://", echo=False)
session = scoped_session(
sessionmaker(
bind=engine,
@meyt
meyt / bot.rb
Created September 18, 2021 14:43 — forked from dideler/bot.rb
Sending a notification message to Telegram using its HTTP API via cURL
# Use this script to test that your Telegram bot works.
#
# Install the dependency
#
# $ gem install telegram_bot
#
# Run the bot
#
# $ ruby bot.rb
#
@meyt
meyt / sqlalchemy_sqlog.py
Last active October 5, 2021 04:39
Log raw SQL queries made by SQLAlchemy
import time
from sqlalchemy import event
class sqlog:
def __init__(self, session_or_engine):
self.engine = (
session_or_engine.get_bind()
if hasattr(session_or_engine, "get_bind")
else session_or_engine
)
@meyt
meyt / pgstat.py
Created October 5, 2021 02:05
Watch active postgres connections and client processes info (name, pid, cmdline)
"""
Watch active postgres connections and client processes info (name, pid, cmdline)
Note: postgres server and clients must be in same machine.
https://gist.github.com/meyt
requirements:
- psycopg2 >= 2.8.5
- psutil >= 5.5.1