Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Touhid Arastu arastu

🏠
Working from home
View GitHub Profile
@arastu
arastu / image_manipulation.py
Created May 4, 2021
Write rtl (Persian, Arabic, Hebrew) text on images using python and pillow
View image_manipulation.py
# 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
arastu / cheatsheet.py
Created Apr 10, 2021 — forked from jacklinke/cheatsheet.py
Django models cheatsheet
View cheatsheet.py
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 / 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"
View keybase.md

Keybase proof

I hereby claim:

  • I am arastu on github.
  • I am arastu (https://keybase.io/arastu) on keybase.
  • I have a public key ASDTglyFyGlXVmDMsuusGrWei9GdBSrTBa3JSJ-Y5PN3HQo

To claim this, I am signing this object:

@arastu
arastu / airpods-toggle.applescript
Last active Mar 29, 2021
Connect/disconnect AirPods automatically on Mac
View airpods-toggle.applescript
-- 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
View python_multiprocessing_queue.py
from multiprocessing import Queue, Process
from time import sleep
def reader_proc(q):
while True:
name = q.get()
print(name)
sleep(2)
if name == 'DONE':
@arastu
arastu / compare-strings.py
Last active Jan 8, 2019
Jaccard algorithms for comparing two strings and return similarity score, Port and refactor https://github.com/aceakash/string-similarity to python
View compare-strings.py
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 / 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())
currentIndex--
let temp = copy[currentIndex]
copy[currentIndex] = copy[randomIndex]
@arastu
arastu / reverse_iter.py
Last active Aug 29, 2018
Problem 1: Write an iterator class reverse_iter, that takes a list and iterates it from the reverse direction. https://anandology.com/python-practice-book/iterators.html
View reverse_iter.py
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">
<body>
<outline text="YouTube Subscriptions" title="YouTube Subscriptions">
<outline text="CS Dojo" title="CS Dojo" type="rss" xmlUrl="https://www.youtube.com/feeds/videos.xml?channel_id=UCxX9wt5FWQUAAz4UrysqK9A" />
<outline text="Stinnett Sticks" title="Stinnett Sticks" type="rss" xmlUrl="https://www.youtube.com/feeds/videos.xml?channel_id=UCiDdaCDetfJBhp5o72UP4xA" />
<outline text="Restore It" title="Restore It" type="rss" xmlUrl="https://www.youtube.com/feeds/videos.xml?channel_id=UCYSAWDQnoz0uIBRYlophvNw" />
<outline text="Black Beard Projects" title="Black Beard Projects" type="rss" xmlUrl="https://www.youtube.com/feeds/videos.xml?channel_id=UC8q2GgxOUS_Dzd5KIYeJQIw" />
<outline text="Andre Will Do It" title="Andre Will Do It" type="rss" xmlUrl="https://www.youtube.com/feeds/videos.xml?channel_id=UCad1pq_FAygE4VaDLJMZ8BA" />
<outline text="Hand Tool Rescue" title="Hand Tool Rescue" type="rss" xmlUrl="