Skip to content

Instantly share code, notes, and snippets.

View singchia's full-sized avatar
🎯
Focusing

singchia

🎯
Focusing
View GitHub Profile
const { NodeVM } = require('vm2');
const vm = new NodeVM({
console: 'inherit',
sandbox: { hello: hello },
require: {
external: false,
builtin: ['fs', 'path'],
}
});
var code = `
const { NodeVM } = require('vm2');
const vm = new NodeVM({
console: 'inherit',
sandbox: {},
require: {
external: false,
builtin: ['fs', 'path'],
}
});
var code = `
@singchia
singchia / tun-ping-linux.py
Created January 7, 2018 09:27 — forked from glacjay/tun-ping-linux.py
Reading/writing Linux's TUN/TAP device using Python.
import fcntl
import os
import struct
import subprocess
# Some constants used to ioctl the device file. I got them by a simple C
# program.
TUNSETIFF = 0x400454ca
TUNSETOWNER = TUNSETIFF + 2
package main
import (
"flag"
"net"
"os"
)
func main() {
var addr string
package main
import (
"flag"
"net"
"os"
"time"
"github.com/singchia/go-hammer/circulinker"
)
@singchia
singchia / Makefile
Created January 31, 2018 13:17 — forked from turtlemonvh/Makefile
Golang Project Makefile Template
# Borrowed from:
# https://github.com/silven/go-example/blob/master/Makefile
# https://vic.demuzere.be/articles/golang-makefile-crosscompile/
BINARY = superdo
VET_REPORT = vet.report
TEST_REPORT = tests.xml
GOARCH = amd64
VERSION?=?
package main
import (
"flag"
"fmt"
"net"
"os"
"sync"
"time"
)
@singchia
singchia / epoll.cpp
Created March 11, 2018 09:06 — forked from dtoma/epoll.cpp
C++ epoll
// https://banu.com/blog/2/how-to-use-epoll-a-complete-example-in-c/
// http://www.kegel.com/poller/
/** Todo
* - [ ] Split i/o and logic
* - [ ] Unit test logic
* - [ ] Logging
* - [ ] Continuous integration
* - [ ] Linux
* - [ ] Windows
@singchia
singchia / gist:0e976ef956451e9b754acc26a1ee6b1f
Created March 14, 2018 09:13 — forked from tonyc/gist:1384523
Using strace and lsof

Using strace and lsof to debug blocked processes

You can use strace on a specific pid to figure out what a specific process is doing, e.g.:

strace -fp <pid>

You might see something like:

select(9, [3 5 8], [], [], {0, 999999}) = 0 (Timeout)

package main
import (
"fmt"
"math/rand"
"os"
"strconv"
"sync"
"time"
)