Skip to content

Instantly share code, notes, and snippets.

View jsonlee0x01's full-sized avatar
🎯
Focusing

Json Lee jsonlee0x01

🎯
Focusing
  • Huawei
  • Beijing, P.R. China
  • 21:01 (UTC +03:00)
View GitHub Profile
@jsonlee0x01
jsonlee0x01 / binary_tree.erl
Created August 19, 2021 15:17 — forked from d11wtq/binary_tree.erl
Binary tree implementation in Erlang.
%% @doc A binary tree implementation in Erlang.
%% A binary tree stores keys and values.
-module(binary_tree).
-export([init/0, init/1, insert/3, lookup/2]).
-define(EMPTY_NODE, {node, 'empty'}).
%% @doc Initialize an empty binary tree node.
%% This is how the root of the tree should be established.
%%
@jsonlee0x01
jsonlee0x01 / pcap.go
Created October 18, 2021 03:43 — forked from landonf/pcap.go
Go C ffi example
/*
* Copyright (c) 2013 Landon Fuller <landonf@mac68k.info>
* All rights reserved.
*/
/* Interface to the native pcap(3) library */
package pcap
/*
#cgo LDFLAGS: -lpcap
#include <pthread.h>
#include <stdio.h>
/* this function is run by the second thread */
void *inc_x(void *x_void_ptr)
{
/* increment x to 100 */
int *x_ptr = (int *)x_void_ptr;
while(++(*x_ptr) < 100);
@jsonlee0x01
jsonlee0x01 / cond.c
Created October 20, 2021 02:23 — forked from rtv/cond.c
An example of using pthread's condition variables, showing how to block a main thread while waiting for worker threads to finish their work, without joining the threads. This could be useful if you want to loop the threads, for example.
#include <pthread.h>
#include <stdio.h>
#include <unistd.h>
#include <assert.h>
/* Compile like this:
gcc --std=c99 -lpthread cond.c -o cond
// gcc setspecific.c -lpthread
/*
Enter Testcase - ./a.out
Create a thread local storage key
pthread_key_create()
========> rc: 0
Create 3 threads using joinable attributes
pthread_create()
========> rc: 0
==> Inside secondary thread
/*
$ gcc tls.c -o tls -lpthread
$ ./tls
1 is runing in thread_func
100 is runing in show
2 is runing in thread_func
200 is runing in show
*/
@jsonlee0x01
jsonlee0x01 / rdtsc.c
Created March 13, 2023 03:18 — forked from savanovich/rdtsc.c
Using RDTSC instruction that returns CPU TSC (Time Stamp Counter)
/*
https://en.wikipedia.org/wiki/Time_Stamp_Counter
https://ru.wikipedia.org/wiki/Rdtsc
*/
#include <stdio.h>
typedef unsigned long long uint64;
int main() {
@jsonlee0x01
jsonlee0x01 / Cache Simulator
Created April 23, 2023 08:57 — forked from markjgap/Cache Simulator
Written in C, program simulates cache logic with a write-back and LRU policy. Handles direct-mapped, set-associative and full-associative caches.
#include <stdlib.h>
#include <stdio.h>
#include <getopt.h>
#include <unistd.h>
#include <math.h> // used to help calculate set and block
#include "cachelab.h"
/*
* Simulates a cache logic with a write-back and LRU (least recently used) policy.
* Handles direct-mapped, set-associative and full-associative caches.
#!/bin/bash
echo '[info-]> Install netmap on Ubuntu'
# Update system
echo '[info-]> Updating system...'
apt-get update
# Install dependencies
echo '[info-]> Installing dependencies ...'
@jsonlee0x01
jsonlee0x01 / gist:f3e66814d714f05d82bfd2223612f33b
Created January 27, 2024 03:21 — forked from chrisdone/gist:02e165a0004be33734ac2334f215380e
Build and run minimal Linux / Busybox systems in Qemu

Common

export OPT=/opt
export BUILDS=/some/where/mini_linux
mkdir -p $BUILDS

Linux kernel