Skip to content

Instantly share code, notes, and snippets.

View arastu's full-sized avatar
🦀

Touhid Arastu arastu

🦀
View GitHub Profile
#!/bin/bash
# Get current status of a OpenFortiVPN connection with options to connect/disconnect.
# Commands that require admin permissions should be whitelisted with 'visudo', e.g.:
# YOURUSERNAME ALL=(ALL) NOPASSWD: /usr/local/bin/openfortivpn
# YOURUSERNAME ALL=(ALL) NOPASSWD: /usr/bin/killall -2 openfortivpn
# To use openfortivpn in an easy way you can create file like: /Documents/.fortivpn-config and put your crential in it as following:
#
# host=123.45.678.9
# port=1234
@arastu
arastu / image_manipulation.py
Created May 4, 2021 13:51
Write rtl (Persian, Arabic, Hebrew) text on images using python and pillow
# First of all you need install *libraqm* on your machin.
# The Raqm library encapsulates the logic for complex text layouts and provides a convenient API.
# libraqm relies on the following libraries: FreeType, HarfBuzz, FriBiDi,
# make sure that you install them before installing libraqm if not available as package in your system.
# if you using macos you can install libraqm with homebrew
# $> brew install libraqm
# Pillow wheels since version 8.2.0 include a modified version of libraqm
$ brew list
==> Formulae
ali gnu-sed libogg mitmproxy recode
aom gnupg libpng mpdecimal rtmpdump
apr gnutls libpq mpfr rubberband
apr-util go libpthread-stubs mpv ruby
argon2 gobject-introspection librist msgpack sdl2
asdf graphite2 librsvg mujs sheldon
aspell graphviz libsamplerate mutagen six
autoconf grep libsndfile ncurses snappy
@arastu
arastu / q.ts
Last active March 6, 2022 06:39
Simple Queue data structure in TypeScript
class Queue<T> {
private list: T[] = [];
private readonly capacity: number | null = null;
private tail = 0;
private head = 0;
constructor(capacity: number) {
this.capacity = Math.max(capacity, 0) || null;
if (this.capacity) {
@arastu
arastu / compare-strings.py
Last active October 11, 2021 07:32
Jaccard algorithms for comparing two strings and return similarity score, Port and refactor https://github.com/aceakash/string-similarity to python
def ngram_string(string, n=3, remove_space=False):
if remove_space:
string = string.replace(' ', '')
if len(string) < n:
return {string: 1}
ngrams = dict()
for i in range(len(string)-n+1):
ngram = string[i:i+n]
@arastu
arastu / server.js
Created August 21, 2021 18:32
Node.js http server with random responses time for testing purposes
const http = require('http');
function randomInt(min, max) {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min + 1)) + min;
}
function randomIDGenerator(length) {
@arastu
arastu / cheatsheet.py
Created April 10, 2021 07:06 — forked from jacklinke/cheatsheet.py
Django models cheatsheet
import uuid
from django.db import models
# Use the import below instead, if using GeoDjango fields
# from django.contrib.gis.db import models
from django.utils.translation import ugettext_lazy as _
from django.contrib.postgres.fields import (
ArrayField,
CICharField,
CIEmailField,
@arastu
arastu / airpods-toggle.applescript
Last active March 29, 2021 08:47
Connect/disconnect AirPods automatically on Mac
-- Forked from: https://coderwall.com/p/fyfp0w/applescript-to-connect-bluetooth-headphones
activate application "SystemUIServer"
tell application "System Events"
tell process "SystemUIServer"
set btMenu to (menu bar item 1 of menu bar 1 whose description contains "bluetooth")
tell btMenu
click
tell (menu item "PUT_YOUR_AIRPODE_NAME_HERE" of menu 1) -- Touhid’s AirPods not Touhid's AirPods
click
if exists menu item "Connect" of menu 1 then
@arastu
arastu / create-cert-and-key-with-certbot.sh
Last active March 15, 2021 04:28
Configuring Harbor with HTTPS Access via letsencrypt(certbot with --standalone flag)
sudo certbot certonly --standalone -d registry.example.com
/**
* Open https://app.snapp.ir
* Login with your credentials
* Copy and pasting this code in developer tools console
* Waiting... :)
*/
(async function () {
function sleep(ms = 0) {
return new Promise(r => setTimeout(r, ms));
}