Skip to content

Instantly share code, notes, and snippets.

View spytheman's full-sized avatar
🏠
Working from home

Delyan Angelov spytheman

🏠
Working from home
View GitHub Profile
@spytheman
spytheman / gist:ba6c0de06dac7adae7d6
Created October 23, 2014 14:26
SSH host aliasing with ~/.ssh/config
Host easyname
User yourloginuser
Hostname vsmchbpmwbl04

Keybase proof

I hereby claim:

  • I am spytheman on github.
  • I am dangelov (https://keybase.io/dangelov) on keybase.
  • I have a public key whose fingerprint is 0184 83C3 E2CD 4640 9697 ABFF 6898 3D29 7686 7866

To claim this, I am signing this object:

@spytheman
spytheman / gist:4f7dca9b5afcf24cfb66652f61d53be4
Created July 6, 2019 11:02
V gg.draw_text_def crashes on Linux
1[13:58:06]delian@nemesis: ~/vbreakout $ gdb ./breakout
GNU gdb (Ubuntu 7.11.1-0ubuntu1~16.5) 7.11.1
Copyright (C) 2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
#!/usr/local/bin/v run
import time
fn myrand_r(seed &u32) int {
mut rs := seed
ns := u32( *rs * u32(1103515245) + u32(12345) )
*rs = ns
return int( ns & u32(0x7fffffff) )
}
0[11:23:46] /v/v $ cat x.v
struct Node {
mut:
head &Node
tail &Node
}
fn (n Node) str() string {
return 'node content: { head: $n.head , tail: $n.tail }'
import time
type Task fn (data voidptr)
pub fn (t Task) str() string {
return 'Task{ ${ptr_str(t)} }'
}
fn task_default(data voidptr){
// println('task_default: $data')
}
@spytheman
spytheman / comparison.txt
Created January 21, 2020 17:22
Performance compare between master and fix/compiler_stuck_at_empty_enum branches.
Summary
'cd /home/delian/.cache/v_at_master ; ./vprod -o source.c examples/hello_world.v ' ran
1.00 ± 0.06 times faster than 'cd /home/delian/.cache/v_at_fix_compiler_stuck_at_empty_enum ; ./vprod -o source.c examples/hello_world.v '
1.09 ± 0.17 times faster than 'cd /home/delian/.cache/v_at_master ; ./vprod -g -o source.c examples/hello_world.v '
1.14 ± 0.06 times faster than 'cd /home/delian/.cache/v_at_fix_compiler_stuck_at_empty_enum ; ./vprod -g -o source.c examples/hello_world.v '
1.77 ± 0.09 times faster than 'cd /home/delian/.cache/v_at_fix_compiler_stuck_at_empty_enum ; ./v -o source.c examples/hello_world.v '
1.79 ± 0.09 times faster than 'cd /home/delian/.cache/v_at_master ; ./v -o source.c examples/hello_world.v '
2.02 ± 0.09 times faster than 'cd /home/delian/.cache/v_at_master ; ./v -g -o source.c examples/hello_world.v '
2.05 ± 0.09 times faster than 'cd /home/del
import os
fn C.scanf()
fn get_cursor_position() (int,int) {
mut x := 0 mut y := 0
C.printf('\033[6n')
C.scanf('\033[%d;%dR', &x, &y)
return x,y
}
fn main(){
print('hello world!')
pub fn header(otext, divider string) string {
cols, _ := get_terminal_size()
mut text := otext
if text.len > 0 {
text = ' $text '
}
// clip the text if it is too long
text = if cols > text.len + 1 + 2*divider.len { text } else { text[0..cols-(1+2*divider.len)] }
// make the text align with the terminal size:
if (text.len % 2) != (cols % 2 ) {
@spytheman
spytheman / f32_vs_f64.v
Created February 26, 2020 20:28
Experiment with f32 vs f64 functions in V.
import math
import benchmark
const ( MAX_REPEATS = 32_000_000 )
type Float = f32 | f64
fn g_sqrt (num Float) Float {
match num {
f32 { return math.sqrtf(it) }
f64 { return math.sqrt(it) }