Skip to content

Instantly share code, notes, and snippets.

Avatar

Ali Utku Selen auselen

  • Sweden
View GitHub Profile
View .tmux.conf
set -g mouse on
set-option -g history-limit 50000
set-window-option -g xterm-keys on
bind '"' split-window -c "#{pane_current_path}"
bind % split-window -h -c "#{pane_current_path}"
bind c new-window -c "#{pane_current_path}"
View closure.go
var hostname = func() func() string {
s, _ := os.Hostname()
return func() string {
return s
}
}()
@auselen
auselen / TLD.md
Created Apr 13, 2017
Root Zone Database stats
View TLD.md

A simple analysis of http://www.iana.org/domains/root/db

$ curl -s http://www.iana.org/domains/root/db | xmllint --html --xpath "//table/tbody/tr/td[1]/span/a|//table/tbody/tr/td[2]|//table/tbody/tr/td[3]" - 2>/dev/null | tr -d '\n' | sed 's/<a[^>]*>/\n/g' | sed -e 's/<[^>]*>/|/g' | awk -F '|' '{print $5,"|",$3}' | sort | uniq -c | sort -rn | awk '{if ($1>4) print $0}'
     51 Amazon Registry Services, Inc. | generic
     43 Charleston Road Registry Inc. | generic
     22 United TLD Holdco Ltd. | generic
     22 Uniregistry, Corp. | generic
     18 Top Level Domain Holdings Limited | generic
     14 Not assigned | country-code
     14 Afilias plc | generic
View tr.md

TR Map

Map

Code

curl -s http://download.maxmind.com/download/worldcities/worldcitiespop.txt.gz \
@auselen
auselen / pi.py
Created Mar 16, 2017
Shorter Pi approximation
View pi.py
from random import random
print 4 * reduce(lambda a, (c, d): (a * (d - 1) + c) / d, ((1.0 if random()**2 + random()**2 <= 1 else 0, i) for i in range(1, 10**6)), 0)
@auselen
auselen / pi.py
Created Mar 14, 2017
Pi approximation
View pi.py
from random import random
l = lambda (a, b), c: (a + c, b + 1)
g = (1 if random()**2 + random()**2 <= 1 else 0 for i in range(10**6))
r, t = reduce(l, g, (0.0, 0))
print r / t * 4
@auselen
auselen / mandelbrot.md
Last active Mar 24, 2017
Drawing Mandelbrot with AWK
View mandelbrot.md

Drawing Mandelbrot with AWK

Mandelbrot

Code

$ LC_ALL=ISO-8859-1 awk 'BEGIN { \
  max=256; \
@auselen
auselen / ♡.md
Last active Mar 24, 2017
Drawing a heart with AWK
View ♡.md

Drawing a heart with AWK

Heart

Math

  • t = 0 → 2𝜋
  • x = 16 sin³(t)
  • y = 13 cos(t) - 5 cos(2 t) - 2 cos(3 t) - cos(4 t)

Code

View π.md

Code

 awk 'BEGIN{srand(); while (++i) {pi += ((rand()**2+rand()**2) <= 1); if ((i%10e5) == 0) printf "%f\n",4*pi/i;}}'

Result

3.140352
3.139892
@auselen
auselen / AWK_Sphere.md
Created Feb 13, 2017
Rendering a sphere with AWK
View AWK_Sphere.md

Rendering a sphere with AWK

Sphere

sphere.gif

Code

LC_ALL=ISO-8859-1 awk 'BEGIN{ \
  pi=atan2(0,-1); r=128; \
  for (j=0; j<360; j+=10) { \
    lx=cos(pi/180*j); ly=sin(pi/180*j); lz=2; lm=sqrt(lx*lx+ly*ly+lz*lz); \
    print "P6"; print r*2,r*2; print "255"; \
You can’t perform that action at this time.