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 / 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 / passwd-generator.py
Created March 19, 2017 11:16
Password generator
# Write a password generator that meets these four criteria:
# 1- The password length is always 4
# 2- The password should consist letters and numbers from {A-F}, {a-f} and {1-6} and pick at least one from each of these(randomly)
# 3- No duplicate passwords generated
# 4- The password is generated totally randomly
array = list('ABCDEFabcdef123456')
count = 0
def print_passwd(passwd):
@anhldbk
anhldbk / install.sh
Last active April 7, 2020 19:52
Install Kong API Gateway on Ubuntu
sudo apt-get install netcat openssl libpcre3 dnsmasq procps perl
# for ubuntu 16.04 (xenial)
sudo apt-get -y install postgresql postgresql-contrib phppgadmin
sudo -i -u postgres
psql
CREATE USER kong; CREATE DATABASE kong OWNER kong;
ALTER USER kong WITH password 'kong';
@anhldbk
anhldbk / TxHandler.java
Created December 31, 2016 14:35
Scrooge Coin
// https://www.coursera.org/learn/cryptocurrency/programming/KOo3V/scrooge-coin
import java.security.PublicKey;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
public class TxHandler {
private UTXOPool pool;
@anhldbk
anhldbk / blockchain.md
Created December 29, 2016 15:57
Blockchain applications

What are non-Bitcoin applications of blockchain technology?

"In 2015 Uber, the world's largest taxi company owns no vehicles, Facebook the world's most popular media owner creates no content, Alibaba the most valuable retailer has no inventory, and Airbnb the world's largest accommodation provider owns no real estate."*

Through collaboration and value distribution, decentralized autonomous organizations (DAOs) will be just as disruptive to the above centralized business models.

Currency

@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 / tor-raw.cpp
Created December 6, 2016 02:38
Working with Tor (C/C++)
// g++ -lstdc++ -Wno-write-strings fetch.cpp -o fetch
#ifdef _WIN32 // Windows
#include <winsock2.h>
#include <ws2tcpip.h>
#define MSG_NOSIGNAL 0
#else // Linux + Mac
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
@anhldbk
anhldbk / event-tree.js
Created November 21, 2016 08:54
Module for matching MQTT-like topics
'use strict'
const _ = require('lodash'),
path = require('path')
/**
* Class for matching MQTT-like topics
*/
class EventTree {
constructor() {