Skip to content

Instantly share code, notes, and snippets.

View sug0's full-sized avatar
💭
debugging

Tiago Carvalho sug0

💭
debugging
View GitHub Profile
@sug0
sug0 / README.md
Last active March 30, 2018 14:34
Small utility to create glitch art

Usage

# show full usage
$ ./glitch -h

# create some glitch art 
$ ./glitch [-o <output.png>] -i <input.(png|jpg)> [-expression <some fancy expression>]
@sug0
sug0 / bytebeat.go
Created May 30, 2018 14:12
Bytebeats in golang
package main
import (
"os"
"io"
"github.com/hajimehoshi/oto"
"github.com/sugoiuguu/go-exit"
)
@sug0
sug0 / goio.c
Created July 15, 2018 17:34
Go style Readers and Writers in C
#include <unistd.h>
#include "goio.h"
#define RWCPY_BUFSIZ 4096
int rwcpy(wfun_t wf, void *dst, rfun_t rf, void *src)
{
static char buf[RWCPY_BUFSIZ];
return rwcpy_r(wf, dst, rf, src, buf, RWCPY_BUFSIZ);
@sug0
sug0 / mandelbrot.go
Last active January 10, 2021 17:39
Simple mandelbrot set visualizer in Go
package main
import (
"os"
"fmt"
"time"
"flag"
"sync"
"image"
"image/png"
@sug0
sug0 / defer.cpp
Last active August 11, 2018 19:16
Go like defer in C++ to guard unsafe code
#include <iostream>
#include <vector>
#include <functional>
#include <cstdio>
#define DEFER(CTX, EXPR) (CTX)->defer([&]() {EXPR;})
class DeferCtx {
std::vector<std::function<void ()>> deferred;
@sug0
sug0 / metaswitch.c
Created August 21, 2018 17:05
Enhanced switch meta control structure in C
#include <stdio.h>
#include <string.h>
#include "metaswitch.h"
int intcmp(const void *x, const void *y)
{
return *(int *)x - *(int *)y;
}
@sug0
sug0 / ast.go
Last active November 12, 2018 19:40
Expression -> AST -> Intermediate code -> C code
package main
import (
"os"
"io"
"fmt"
"unicode"
)
type ASTNode interface {
@sug0
sug0 / pick.c
Created November 27, 2018 23:35
Windows utility that picks an RGB color, returning it's hex representation
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <windows.h>
// cc -Wall -O2 -o pick.exe pick.c -lcomdlg32
COLORREF fromhexstr(const char *hex)
{
COLORREF color = 0;
@sug0
sug0 / example.go
Last active January 12, 2019 23:57
Very simple Go allocator
package main
/*
typedef struct {
int x, y;
} Point;
void init_pt(Point *p, int x, int y)
{
p->x = x;
@sug0
sug0 / tunnel.go
Created January 12, 2019 13:50
TCP --> TLS tunnel in go
package main
import (
"io"
"net"
"flag"
"sync"
"crypto/tls"
)