Tag: development

Untyped Constants in Golang

Golang is extremely explicit with types. It supports constants of a type. But how about a const 2 or hello. What type would they assume!? Go solved this problem with untyped constants. Untyped means: A constant’s type depends on the type of assignee variable. The assignee’s type must […]

Ubiquitous Client for Redis Server: Netcat

Forget about redis-cli. Just use nc bash-5.0# nc -v 10.x.x.x 6379 10.x.x.x (10.x.x.x:6379) open select 14 +OK What is ncat? NAME nc — arbitrary TCP and UDP connections and listens SYNOPSIS nc [-46AcDCdhklnrtUuvz] [-b boundif] [-i interval] [-p source_port] [-s source_ip_address] [-w timeout] [-X proxy_protocol] [-x proxy_address[:port]] [–apple-delegate-pid […]

SIngle Thread LRUCache in C++

#include <iostream> #include <list> #include <unordered_map> using namespace std; size_t capacity; class LRUCache { public: bool Lookup(int key, int *price) { auto it = hash_table.find(key); if (it == hash_table.end()) { return false; } *price = it->second.second; // update the key in the queue MoveToFront(key, it); return true; } […]

Notes on Go Structure Tags

Go has a feature to create a user-defined type with struct. Go also allows the program to specify meta-information with structure field. This meta-information is called Tags. A tag usually helps in packaging/unpacking a user-defined type structure. package main import ( “encoding/json” “fmt” ) type Test struct { […]