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

AI: Where in the Loop Should Humans Go?

This is a re-publishing of a blog post I originally wrote for work, but wanted on my own blog as well.AI is everywhere, and its impressive claims are leading to rapid adoption. At this stage, I’d qualify it as charismatic technology—someth…

via Ferd.ca

More Good Programming Quotes, Part 6

Here are more good programming quotes I have found since my last post. Programming “Configuration is coding in a poorly designed programming language without tests, version control, or documentation.”Gregor Hohpe “It’s the developers misunderstanding, not…

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