Skip to content

Instantly share code, notes, and snippets.

Thanks to ///https://medium.com/@ryardley/react-hooks-not-magic-just-arrays-cd4f1857236e
let state = [];
let setters = [];
let firstRun = true;
let cursor = 0;
function createSetter(cursor) {
return function setterWithCursor(newVal) {
state[cursor] = newVal;
@tonis2
tonis2 / gist:7975cab032cb7703a3572b31bb97599f
Created December 13, 2018 21:36
Caylel, save data and load with graphql
package main
import (
"bytes"
"context"
"encoding/json"
"fmt"
"log"
"math/rand"
"strings"
@tonis2
tonis2 / gist:32bde0938b2c9cdbe44ab0317a7ec7fe
Created January 29, 2019 10:46
Golang struct to graphql schema
func makeSchemaValues(Types interface{}) (graphql.Fields, graphql.FieldConfigArgument) {
fields := make(graphql.Fields)
args := make(graphql.FieldConfigArgument)
val := reflect.ValueOf(Types)
if val.Kind() == reflect.Ptr {
val = reflect.Indirect(val)
1 sudo nano /etc/default/grub
2 There is a line in that: GRUB_CMDLINE_LINUX_DEFAULT="quiet splash" (like this), replace with: GRUB_CMDLINE_LINUX_DEFAULT="quiet splash intel_idle.max_cstate=1"
3 Save it (CTRL+O)
4 sudo update-grub
5 sudo reboot
@tonis2
tonis2 / proxy.js
Last active February 27, 2019 09:13
ES6 light version of Object observing + easy to listen state change
export default class Observer {
constructor(data) {
this.listeners = []
this.preproxy = new WeakMap()
this.state = this.proxify(data, [])
}
listen(callback) {
this.listeners.push(callback)
@tonis2
tonis2 / gist:72c334f19c38753df0d0cc0864ec72b1
Created April 23, 2019 23:06
Detect website url changes
/* These are the modifications: */
history.pushState = (f =>
function pushState() {
var ret = f.apply(this, arguments)
window.dispatchEvent(new Event("pushState"))
window.dispatchEvent(new Event("locationchange"))
return ret
})(history.pushState)
history.replaceState = (f =>
sudo apt-get install libxi-dev libglfw3-dev libglfw3
@tonis2
tonis2 / gist:a689d9d55ceadc55a23158a102f9fb8e
Created June 4, 2019 06:49
Async websocket calls with ES6
const marker = () => {
return Math.random()
.toString(36)
.slice(2)
.padStart(10, "0")
}
export default class AsyncSocket {
constructor(url = null, config = {}) {
this.url = url
@tonis2
tonis2 / Caddy_Digitalocean.md
Created October 1, 2020 15:43
How to install Caddy on Linux 20.04 at Digitalocean
@tonis2
tonis2 / help.zig
Last active January 24, 2021 16:56
const std = @import("std");
const print = std.debug.print;
pub const Vec3 = packed struct {
x: u32,
y: u32,
z: u32,
pub fn new(x: u32, y: u32, z: u32) Vec3 {
return Vec3{