Skip to content

Instantly share code, notes, and snippets.

Working from home

Touhid Arastu arastu

Working from home
View GitHub Profile
arastu /
Created May 4, 2021
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
arastu /
Created Apr 10, 2021 — forked from jacklinke/
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 (
arastu / current_track.applescript
Last active Nov 27, 2020
update twitter bio and add current playing song from Spotify to it
View current_track.applescript
on escape_quotes(string_to_escape)
set AppleScript's text item delimiters to the "\""
set the item_list to every text item of string_to_escape
set AppleScript's text item delimiters to the "\\\""
set string_to_escape to the item_list as string
set AppleScript's text item delimiters to ""
return string_to_escape
end escape_quotes
tell application "Spotify"

Keybase proof

I hereby claim:

  • I am arastu on github.
  • I am arastu ( on keybase.
  • I have a public key ASDTglyFyGlXVmDMsuusGrWei9GdBSrTBa3JSJ-Y5PN3HQo

To claim this, I am signing this object:

arastu / airpods-toggle.applescript
Last active Mar 29, 2021
Connect/disconnect AirPods automatically on Mac
View airpods-toggle.applescript
-- Forked from:
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
tell (menu item "PUT_YOUR_AIRPODE_NAME_HERE" of menu 1) -- Touhid’s AirPods not Touhid's AirPods
if exists menu item "Connect" of menu 1 then
from multiprocessing import Queue, Process
from time import sleep
def reader_proc(q):
while True:
name = q.get()
if name == 'DONE':
arastu /
Last active Jan 8, 2019
Jaccard algorithms for comparing two strings and return similarity score, Port and refactor 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 / shuffle.js
Created Sep 30, 2018
Shuffle a JavaScript array
View shuffle.js
Array.prototype.shuffle = function () {
var copy = this.concat()
var currentIndex = copy.length
while (currentIndex !== 0) {
let randomIndex = Math.floor(currentIndex * Math.random())
let temp = copy[currentIndex]
copy[currentIndex] = copy[randomIndex]
arastu /
Last active Aug 29, 2018
Problem 1: Write an iterator class reverse_iter, that takes a list and iterates it from the reverse direction.
class reverse_iter:
def __init__(self, l):
self.l = l[::-1]
self.i = 0
def __iter__(self):
return self
def __next__(self):
if self.i < len(self.l):
View subscription_manager.xml
<opml version="1.1">
<outline text="YouTube Subscriptions" title="YouTube Subscriptions">
<outline text="CS Dojo" title="CS Dojo" type="rss" xmlUrl="" />
<outline text="Stinnett Sticks" title="Stinnett Sticks" type="rss" xmlUrl="" />
<outline text="Restore It" title="Restore It" type="rss" xmlUrl="" />
<outline text="Black Beard Projects" title="Black Beard Projects" type="rss" xmlUrl="" />
<outline text="Andre Will Do It" title="Andre Will Do It" type="rss" xmlUrl="" />
<outline text="Hand Tool Rescue" title="Hand Tool Rescue" type="rss" xmlUrl="