Skip to content

Instantly share code, notes, and snippets.

View hoangpq's full-sized avatar
🏠
Working from home

Hoang Phan hoangpq

🏠
Working from home
View GitHub Profile
import selectors
import socket
selector = selectors.DefaultSelector()
server_socket = socket.socket()
server_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
server_address = ("127.0.0.1", 1234)
server_socket.setblocking(False)
@hoangpq
hoangpq / Profile Rust on Linux.md
Created June 11, 2020 16:21 — forked from KodrAus/Profile Rust on Linux.md
Profiling Rust Applications

Profiling performance

Using perf:

$ perf record -g binary
$ perf script | stackcollapse-perf.pl | rust-unmangle | flamegraph.pl > flame.svg

NOTE: See @GabrielMajeri's comments below about the -g option.

@hoangpq
hoangpq / borrow_vs_as_ref.rs
Created May 10, 2020 14:20 — forked from koute/borrow_vs_as_ref.rs
Rust: Borrow vs AsRef
#![allow(non_snake_case)]
#![allow(dead_code)]
use std::borrow::Borrow;
use std::convert::AsRef;
struct Y;
struct X {
y: Y
@hoangpq
hoangpq / controller.py
Created November 22, 2019 09:34
Odoo Asyncio Example
# -*- coding: utf-8 -*-
from odoo import http
import aiohttp
import asyncio
import time
import json
async def get_json(client, url):
@hoangpq
hoangpq / CMakeLists.txt
Created January 15, 2019 04:40 — forked from squeek502/CMakeLists.txt
Lua 5.3.x Windows CMake build script
project ( lua C )
cmake_minimum_required ( VERSION 2.8 )
include_directories ( src ${CMAKE_CURRENT_BINARY_DIR} )
set ( SRC_CORE src/lapi.c src/lcode.c src/lctype.c src/ldebug.c src/ldo.c src/ldump.c src/lfunc.c src/lgc.c src/llex.c
src/lmem.c src/lobject.c src/lopcodes.c src/lparser.c src/lstate.c src/lstring.c src/ltable.c
src/ltm.c src/lundump.c src/lvm.c src/lzio.c )
set ( SRC_LIB src/lauxlib.c src/lbaselib.c src/lbitlib.c src/lcorolib.c src/ldblib.c src/liolib.c
src/lmathlib.c src/loslib.c src/lstrlib.c src/ltablib.c src/lutf8lib.c src/loadlib.c src/linit.c )
--log_gc (Log heap samples on garbage collection for the hp2ps tool.)
type: bool default: false
--expose_gc (expose gc extension)
type: bool default: false
--max_new_space_size (max size of the new generation (in kBytes))
type: int default: 0
--max_old_space_size (max size of the old generation (in Mbytes))
type: int default: 0
--max_executable_size (max size of executable memory (in Mbytes))
type: int default: 0
// Multiplexed PWM RGB Led Demo
// By Petri Hakkinen
// 24th November 2014
//
// Arduino Uno driving a single RGB led with only one resistor.
//
// Make the following connections:
// * Connect Arduino pins D2,D3,D3 to anodes of a RGB led.
// * Connect cathode of the RGB led to 330 ohm resistor.
// * Connect the other end of the resistor to ground.
@hoangpq
hoangpq / addTwo.wast
Created November 26, 2018 08:44 — forked from kanaka/addTwo.wast
Run wast (WebAssembly) in node
(module
(func $addTwo (param i32 i32) (result i32)
(i32.add
(get_local 0)
(get_local 1)))
(export "addTwo" (func $addTwo)))
@hoangpq
hoangpq / task.go
Last active November 3, 2018 09:28
Simple task queue in Golang
package main
import (
"fmt"
"github.com/satori/go.uuid"
"math/rand"
"sync"
"time"
)
#include <unistd.h>
#include <node.h>
#include <string.h>
#include <v8.h>
using namespace v8;
unsigned long long count = 0;
// native blocking/compute intensive function