Skip to content

Instantly share code, notes, and snippets.

View arastu's full-sized avatar
🦀

Touhid Arastu arastu

🦀
View GitHub Profile
@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 / 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]
@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):
<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 / 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
@arastu
arastu / anisble-playbook.sh
Last active August 18, 2018 12:04
Fix MacOS(OSX) crash complaining of operation `in progress in another thread when fork() was called` when calling ansible-playbook
alias ansible-playbook="OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES; ansible-playbook"
@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 / 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
@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
# client ----> 1.1.1.1 --------> 2.2.2.2
# (relay) (dest)
sudo iptables -A FORWARD -d 2.2.2.2 -i ens160 -p udp -m udp --dport 500:500 -j ACCEP
sudo iptables -A FORWARD -d 2.2.2.2 -i ens160 -p udp -m udp --dport 4500:4500 -j ACCEPT
sudo iptables -t nat -A PREROUTING -d 1.1.1.1 -p udp -m udp --dport 500:500 -j DNAT --to-destination 2.2.2.2
sudo iptables -t nat -A PREROUTING -d 1.1.1.1 -p udp -m udp --dport 4500:4500 -j DNAT --to-destination 2.2.2.2
sudo iptables -t nat -A POSTROUTING -o ens160 -j MASQUERADE