Skip to content

Instantly share code, notes, and snippets.

View netgusto's full-sized avatar
:bowtie:

netgusto netgusto

:bowtie:
View GitHub Profile
@netgusto
netgusto / siginfo.go
Last active November 11, 2022 10:02
SIGINFO (Ctrl+t) to dump live metrics in go
// Send SIGINFO (Ctrl+t on the shell, or kill -info <pid>)
// To dump live metrics
go func() {
sigs := make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGINFO)
for range sigs {
duration := time.Since(start)
// obviously adapt this next line to your need :)
logger.Info(fmt.Sprintf("Processed %d jobs in %s; Throughput=%.4f/s\n", nbprocessed, duration.String(), float64(nbprocessed)/duration.Seconds()))
@jimmychu0807
jimmychu0807 / string-conversion.rs
Created November 21, 2019 10:20
Conversion between String, str, Vec<u8>, Vec<char> in Rust
use std::str;
fn main() {
// -- FROM: vec of chars --
let src1: Vec<char> = vec!['j','{','"','i','m','m','y','"','}'];
// to String
let string1: String = src1.iter().collect::<String>();
// to str
let str1: &str = &src1.iter().collect::<String>();
// to vec of byte
@munificent
munificent / generate.c
Last active September 15, 2024 03:16
A random dungeon generator that fits on a business card
#include <time.h> // Robert Nystrom
#include <stdio.h> // @munificentbob
#include <stdlib.h> // for Ginny
#define r return // 2008-2019
#define l(a, b, c, d) for (i y=a;y\
<b; y++) for (int x = c; x < d; x++)
typedef int i;const i H=40;const i W
=80;i m[40][80];i g(i x){r rand()%x;
}void cave(i s){i w=g(10)+5;i h=g(6)
+3;i t=g(W-w-2)+1;i u=g(H-h-2)+1;l(u
@hazkaz
hazkaz / zigzag.js
Created January 18, 2018 17:23
zigzag PID bot
const { vector, comm } = require("bytearena-sdk");
const Vector2 = vector.Vector2;
const agent = comm.connect();
let count = 1
const countLimit = 55
let countDirection = 1
let first = true
let angle = 0
agent.on("perception", perception => {
@MichaelFedora
MichaelFedora / playcanvas-stable.d.ts
Last active December 29, 2017 14:20
PlayCanvas Engine Typings (wip). Use it by downloading and placing both this and `playcanvas-stable.js` in the same directory.
/**
* PlayCanvas Engine Typings
*
* Use it by downloading and placing both this and `playcanvas-stable.js` in the same directory.
*
* (c) 2017 Michael Fedora (michaelfedora.github.io)
* Licensed under MIT.
*/
type DomKeyboardEvent = KeyboardEvent;
@tzmartin
tzmartin / Info.plist
Created June 24, 2017 19:31 — forked from nathankerr/Info.plist
Registering a Go app as a protocol handler under Mac OS X
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleExecutable</key>
<string>myapp</string>
<key>CFBundleIdentifier</key>
<string>com.pocketgophers.myapp</string>
<key>CFBundleURLTypes</key>
<array>
@myshov
myshov / function_invocation.js
Last active August 19, 2024 12:23
11 Ways to Invoke a Function
console.log(1);
(_ => console.log(2))();
eval('console.log(3);');
console.log.call(null, 4);
console.log.apply(null, [5]);
new Function('console.log(6)')();
Reflect.apply(console.log, null, [7])
Reflect.construct(function(){console.log(8)}, []);
Function.prototype.apply.call(console.log, null, [9]);
Function.prototype.call.call(console.log, null, 10);
@servercharlie
servercharlie / client.js
Last active March 28, 2019 13:31
Proper Socket.IO Latency Checking
/*
- Insert this after including / referencing socket.io.min.js.
- Point being:
- Client sockets *naturally* adapts its Ping Interval & Ping Timeout
from its server's settings, hence you can't actually those options here.
- We instead add an eventhandler for the "pong", and the actual millisecond latency,
and optionally to the "ping" too, in case you wanna see it in action.
- References:
@nathankerr
nathankerr / Info.plist
Last active September 28, 2024 00:41
Registering a Go app as a protocol handler under Mac OS X
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleExecutable</key>
<string>myapp</string>
<key>CFBundleIdentifier</key>
<string>com.pocketgophers.myapp</string>
<key>CFBundleURLTypes</key>
<array>
@avafloww
avafloww / PhpJava.java
Last active June 13, 2024 07:36
This snippet of code is syntactically valid in both PHP and Java, and produces the same output in both.
/*<?php
//*/public class PhpJava { public static void main(String[] args) { System.out.printf("/*%s",
//\u000A\u002F\u002A
class PhpJava {
static function main() {
echo(//\u000A\u002A\u002F
"Hello World!");
}}
//\u000A\u002F\u002A
PhpJava::main();