Skip to content

Instantly share code, notes, and snippets.

View meysampg's full-sized avatar
🖖
bit bit 0 bit

Meysam P. Ganji meysampg

🖖
bit bit 0 bit
View GitHub Profile
@meysampg
meysampg / Logger.go
Last active July 30, 2019 08:12
get logger
package services
import (
"github.com/sirupsen/logrus"
)
type Logger interface {
// formatted methods
Debugf(format string, args ...interface{})
Infof(format string, args ...interface{})
from contextlib import ExitStack
from functools import partial
# In some situation it's needed to care about program termination, explicitly or implicitly (by kill or raising an
# exception in the flow), situation likes send a notification on termination. For this purpose we can use contextlib
# of Python. Define our callbacks and put our main in an ExitStack. For more information see
# https://docs.python.org/3/library/contextlib.html#contextlib.ExitStack
def printStars():
@meysampg
meysampg / sql_timestamp_js.js
Created August 31, 2019 12:41
return a ready to use timestamp for SQL
new Date().toISOString().split('.')[0].split('T').join(' ')
# "2019-08-31 12:40:44"
sed -i "1s/[A-Z]/\L&/g" FILENAME
@meysampg
meysampg / reset_pk.sql
Created September 5, 2019 16:24
Reset Primary Key of a table
ALTER TABLE `test` DROP `id`;
ALTER TABLE `test` AUTO_INCREMENT = 1;
ALTER TABLE `test` ADD `id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST;
@meysampg
meysampg / between_finder.sh
Created September 5, 2019 16:30
Find all files which accessed between now and 50 minutes ago
SEARCH_DIR="/path/to/directory"
FORMAT="%Y-%m-%d %H:00:00"
find $SEARCH_DIR -newerat "`date -d "-50minutes" +"$FORMAT"`" ! -newerat "`date +"$FORMAT"`"
@meysampg
meysampg / removeSimilarKeyFromDictionary.py
Created September 11, 2019 15:42
remove similar key from a dictionary and put the longest key as the final key
def removeSimilarKeyFromDictionary(d, key):
for s in d.keys():
if key.find(s) != -1:
# True with a non-empty list mean the given key is the final key, but it has a candidate on list
return True, s
elif s.find(key) != -1:
# False with a non-empty list mean the iterator key is the final key and its value should sum with
# the value of returned key
return False, s
# define alternatives
update-alternatives --install /usr/bin/java java /opt/lib/jdk/bin/java 100
update-alternatives --install /usr/bin/javac javac /opt/lib/jdk/bin/javac 100
update-alternatives --install /usr/bin/javaws javaws /opt/lib/jdk/bin/javaws 100
# do config
update-alternatives --config java
update-alternatives --config javac
update-alternatives --config javaws
# install libraries
apt install libgtk2.0-0
apt install libgconf-2-4
# install xvfb to run orca as a server without graphical environment
apt install xvfb
# install electron
npm install -g [email protected] --allow-root --unsafe-perm
@meysampg
meysampg / select_and_translate.sh
Last active October 30, 2019 16:15
translate word and send notify
#!/usr/bin/env bash
translate() {
notify-send "$1" $(trans -no-bidi -b :@fa "$1")
}
select_and_translate() {
translate "$(xclip -out -selection primary)"
}