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 / x.v
Last active August 2, 2020 12:39
draw V logo
// Build this example with
// v -live bounce.v
module main
import gx
import gg
import time
struct Game {
mut:
// Build this example with
// v -live bounce.v
module main
import gx
import gg
import time
import sokol.gfx
struct Game {
// Build this example with
// v -live bounce.v
module main
import gx
import gg
import time
import sokol.gfx
struct Game {
// Build this example with
// v -live bounce.v
module main
import os
import gx
import gg
import time
struct Game {
// Build this example with
// v -live bounce.v
module main
import os
import gx
import gg
import time
struct Game {
import time
import rand
fn quicksort<T>(mut tab []T, left, right int) {
pt := &T(tab.data)
mut i := left
mut j := right
middle := (left + right) >> 1
mut pivot := unsafe {*(pt + middle)}
for {
fn new_counter_generator() fn () int {
mut count := -1
return fn () int {
count = count + 1
return count
}
}
fn main() {
a := new_counter_generator()
import sync
enum FSMState {
init = 0
state_a
state_b
state_c
exit
}
@spytheman
spytheman / mmap_example.v
Last active September 19, 2020 04:58
Example of using mmap on linux in vlang
import os
#include <sys/mman.h>
fn C.mmap(addr voidptr, len size_t, prot, flags, fd int, offset i64) voidptr
fn C.munmap(addr voidptr, len size_t) int
fn main() {
big_file_path := '/ssd2/VirtualBox VMs/ISOs/ClearOS-DVD-x86_64-7.7.2.280072.iso'
fsize := os.file_size(big_file_path)
@spytheman
spytheman / vbytebeat.v
Last active October 10, 2020 09:49
bytebeat like sounds in V (updated to sound more like the original)
import time
import sokol.audio
const (
sw = time.new_stopwatch({})
sw_start_ms = sw.elapsed().milliseconds()
frame_0 = int(0)
)
fn my_audio_stream_callback(buffer &f32, num_frames, num_channels int) {