Skip to content

Instantly share code, notes, and snippets.

View anhldbk's full-sized avatar
🌴
Calm

Anh Le (Andy) anhldbk

🌴
Calm
View GitHub Profile
@anhldbk
anhldbk / lock_benchmarks.cpp
Created July 5, 2017 08:04
Benchmark for various locking strategies
#include <sys/stat.h>
#include <atomic>
#include <stdio.h>
#include <stdint.h>
#include <assert.h>
#include <map>
#include <iostream>
#include <string.h>
#include <thread>
#include "lock/RwLock.h"
@anhldbk
anhldbk / atomic_reference.cpp
Created July 5, 2017 03:53
Atomic references
#include <atomic>
#include <iostream>
#include <thread>
#include <stdint.h>
using namespace std;
void run_in_pool(std::function<void() > routine, uint8_t max_thread = 4) {
std::thread modifiers[max_thread];
uint8_t i;
@anhldbk
anhldbk / example.cpp
Created July 5, 2017 03:17
C/C++ : Returning values by reference
uint32_t counter = 0;
uint32_t& get_counter(){
return counter;
}
int main(){
uint32_t _counter = get_counter();
_counter += 1;
cout << _counter << endl; // print 1
@anhldbk
anhldbk / fill_parentheses.py
Created March 26, 2017 16:35
Print all combinations of balanced parentheses
def fill(array, pos, count = 0):
max_count = len(array) / 2
if pos >= len(array ):
if count == 0:
print array
return
label = {
1: '{',
-1: '}'
@anhldbk
anhldbk / heapify.cpp
Last active March 22, 2017 07:41
Heapify routine for Min-Max Heap
// This is a minor modificatioin for the one wrongly implemented in http://www.geeksforgeeks.org/median-of-stream-of-integers-running-integers/
// Heapification
// Note that, for the current median tracing problem
// we need to heapify only towards root, always
void heapify(int i, bool down= false)
{
if (!down){
// heapify up
int p = parent(i);
@anhldbk
anhldbk / decorators.js
Created December 8, 2016 04:48
ES6 Decorators Example
// Demo on how to use ES6 decorators
// HOW TO RUN
// $ yarn add --dev babel-plugin-transform-decorators-legacy
// $ babel-node --plugins transform-decorators-legacy test.js
'use strict'
@meta({
manufacturer: 'evolas'
})
class Data {
@anhldbk
anhldbk / machine-id.js
Created August 10, 2016 04:35
Get globally unique IDs for machines
'use strict'
const os = require('os')
const crypto = require( "crypto" )
const _ = require('lodash')
// Get MAC addresses of public interfaces
// @return: List of addresses
function getPublicInterfaces(){
// get network interfaces
@anhldbk
anhldbk / wifi.md
Last active June 15, 2016 10:08
Install non-free wifi driver on my Ubuntu (Dell N4010)

Motivation

My Dell N4010's wifi driver seems not to work well on Ubuntu.

1. Run command

sudo vim /etc/apt/sources.list

2. Add following lines: