Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/awk -f
function max_value(new_value, old_value)
{
if (new_value > old_value)
{
return new_value;
}
else
{
#!/usr/bin/awk -f
function remove_quotes(s) {
return substr(s, 2, length(s) - 2)
}
BEGIN {FS = ","}
{printf "%s,%s,%s,%s\n", remove_quotes($4), remove_quotes($5), remove_quotes($6), remove_quotes($7)}
# If you're looking into the C10M problem (10 million concurrent connections)
# you might want to play with DPDK (Originally proprietry Intel, now open source)
#
# C10M: http://c10m.robertgraham.com/
# DPDK: http://dpdk.org/
#
# This is a quick summary how to install dpdk on ubuntu
# running inside virtualbox on a mac
# On my Mac:
@NanXiao
NanXiao / parse_mem_info.cpp
Created June 4, 2019 05:59
Parse /proc/meminfo file
#include <fstream>
#include <iostream>
#include <sstream>
#include <string>
int main()
{
const std::string meminfo_file("/proc/meminfo");
std::ifstream ifs(meminfo_file);
@NanXiao
NanXiao / nmi-interrupts.txt
Created May 27, 2019 05:22 — forked from wmealing/nmi-interrupts.txt
NMI interrupts and the joy they bring.
A non-maskable interrupt (NMI) is an interrupt type which differs from standard interrupt mechanism by enforcing attention from the interrupt processor (usually the CPU). This solution discusses an NMI is in more depth and how they are handled.
### What is an Interrupt ? ###
Modern systems architecture has created tightly coupled connect between system components. Work for components can be handed off to a component for completion. Rather than wait for the component the main CPU can be tasked to do other pending work.
When the component has completed its work it will raise a signal to the main processor. The main processor considers this signal an "interrupt", as the current work on the CPU will be interrupted immediately Each component has a number assigned to it.
### Why "mask" an interrupt ? ###
#include <stdio.h>
#include <unistd.h>
#include <sys/time.h>
#define CPU_NUM (104)
#define LOOP_NUM (100)
#define ARRAY_SIZE (CPU_NUM * LOOP_NUM)
double a[ARRAY_SIZE], b[ARRAY_SIZE], c[ARRAY_SIZE];
@NanXiao
NanXiao / nccl_ex.cu
Last active December 22, 2017 09:43
/* compile:
* /opt/cuda/bin/nvcc -ccbin g++ -gencode=arch=compute_60,code=sm_60 -std=c++11 -O3 -I/usr/local/nccl/include/ -L/opt/cuda/lib64 -lcudart -lrt -L/usr/local/nccl/lib -lcurand -lnccl -lnvToolsExt -o nccl_ex nccl_ex.cu
*/
#include "nccl.h"
#include <stdio.h>
#define GPU_COUNT (4)
#define CUDACHECK(cmd) do { \
@NanXiao
NanXiao / bfd_test.c
Created October 17, 2017 03:01
A simple bfd usage example
#define PACKAGE "bfd_test"
#include <iostream>
#include <bfd.h>
int main(int argc, char** argv)
{
if (argc == 1)
{
std::cout << "Lack input file!\n";
return 1;
package main
import (
"fmt"
"net/http"
"encoding/json"
)
func main() {
req, _ := http.NewRequest("GET", "https://api.clever.com/v1.1/sections", nil)
@NanXiao
NanXiao / server.go
Created August 11, 2016 10:42
server.go
package main
import (
"log"
"net/http"
"github.com/gorilla/mux"
"encoding/json"
"strconv"
"sync"
)