Skip to content

Instantly share code, notes, and snippets.

View arastu's full-sized avatar
🦀

Touhid Arastu arastu

🦀
View GitHub Profile
@arastu
arastu / ipof.sh
Last active August 18, 2018 12:15
#!/bin/bash
# Googooli bash function for resolve a hostname to the first IP address or find your public ip address
# Example:
# $ ipof www.google.com
# 216.58.204.132
# find your public ip address when nothing is sent
# $ ipof
# x.x.x.x
{
{ 'A', ".-" },
{ 'B', "-..." },
{ 'C', "-.-." },
{ 'D', "-.." },
{ 'E', "." },
{ 'F', "..-." },
{ 'G', "--." },
{ 'H', "...." },
{ 'I', ".." },
@arastu
arastu / duck-typing.js
Last active August 21, 2018 21:48
If it looks like a duck and quacks like a duck, it's a duck
// This is a classical example of dependency injection.
// My class Car receives an instance of an engine and use it in the run method, where it calls the turnOn method.
// Note that my Car does not depends on any concrete implementation of engine.
// And I'm not importing any other type! Just using a dependency injected instance of something
// that responds to a turn_on message. I could say my class Car depends on an interface.
// But I did not have to declare it. It is an automatic interface!
class Car {
constructor(engine) {
this.engine = engine
<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="
@arastu
arastu / reverse_iter.py
Last active August 29, 2018 22:19
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
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):
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 / fucker.sh
Created August 11, 2018 14:44
delete all docker resource
#!/usr/bin/env bash
docker ps -a -q | xargs docker rm -f
docker images -a -q | xargs docker rmi -f
docker volume ls -q | xargs docker volume rm -f
docker network ls | xargs docker network rm
docker system prune -f
@arastu
arastu / shuffle.js
Created September 30, 2018 22:49
Shuffle a JavaScript array
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]

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 / current_track.applescript
Last active November 27, 2020 19:52
update twitter bio and add current playing song from Spotify to it
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"