Snippet Paylasma Servisi

March 15, 2021

Çoğu yazılımcı gibi snippet paylaşmak istediğim zaman github’ ın gist servisini kullanıyordum. Gistlerin miktarı arttıkça aradığımı bulamaz oldum. Arama özelliklerini yetersiz bulduğum için bu dosyaları kendim host etmeye kadar verdim. Aynı zamanda ag veya ack gibi araçlarla istediğim zaman arama yapabilme bulk halde isleyebilme gibi avantajları da var.

Kendim host ettiğim dosyalara erişmek için basit bir komut satırı aracı ve server lazım geldi. Onun için snippet paylaşma servisi paster ı yazdım. İmplemantasyon 100 satırın altında 2 dosyadan oluşuyor.

E servisi yazdık da var olan gistler ne olacak? Birinin gistleri indiren bir script yazması lazım. İnternette aradım mamafih düzgün çalışan bir şey bulamadım. Madem benim ihtiyacım oldu yazdım. Birilerinin de ihtiyacı olur diye paylaşıyorum.

Çalıştırdığınız dizinde meta, rawurls, files isimli dosya/dizinleri silmeye çalışır bunları bulundurmayın.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# it tries to delete meta, rawurls and files
# Requires jq
GITHUB_USER="<set your github username here>"
TOKEN="<set your token here>"
HEADER="Accept: application/vnd.github.v3+json"

rm meta && touch meta
rm rawurls && touch rawurls
mkdir -p files

for i in {1..14..1}
do
	content=$(curl -s -u $GITHUB_USER:$TOKEN -H '$HEADER' "https://api.github.com/gists?page=$i")
	echo $content | jq '.[].files | to_entries| .[].value.raw_url' >> meta
	sleep 3
done

sed 's/"/ /g' meta > rawurls

while read -r line;
do
	filename=$(echo $line | cut -d '/' -f 8-)
	randx=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 1 | head -n 1)
	
	if [[ ! -f "files/$filename" ]]; then # if file not exists create it
		curl -s $line --output files/$filename
	else # if file is already exist, then add random char prefix to file
		curl -s $line --output files/$randx$filename
	fi

	sleep 3
done < rawurls

hidden

The Review Is the Action Item

2024/05/30The Review Is the Action ItemI like to consider running an incident review to be its own action item. Other follow-ups emerging from it are a plus, but the point is to learn from incidents, and the review gives room for that to happen.This is no…

via Ferd.ca

Finding a New Software Developer Job

For the first time ever, I was laid off, and had to find a new software developer job. I managed to find a new one, but it took longer than I thought, and it was a lot of work. I … Continue reading →

via Henrik Warne's blog

HOWTO: Change your behavior

In theory, behavior change should be easy. At first glance, it seems like you control your behavior. So, if you desire different behavior, why doesn’t your behavior change as instantly as your desire to change it? In short, lasting change of habitual behavio…

via Matt Might's blog