Skip to content

Instantly share code, notes, and snippets.

@qlife
qlife / bsearch.cpp
Created January 11, 2021 02:08
Implement the Binary Search Algorithm
/*
* Gotcha
*
* 1. mid = left + (right-left) / 2;
*
* To prevent overflow during (left+right)
*
* 2. while(left <= right)
*
* 3. compare (==) case firstly.
@qlife
qlife / install.sh
Created April 24, 2019 02:16
Fonts for Manchu Scripts and Phags-pa scripts.
#!/bin/bash
sudo apt-get install fonts-manchufont
sudo apt-get install fonts-noto
import asyncio
import threading
import time
class XYZ(threading.Thread):
def __init__(self):
super().__init__()
self.val = 0
self.isRunning = False
@qlife
qlife / mini_benchmark_deque.py
Created December 6, 2018 08:27
Mini-benchmark of Deque
import collections
L = list(range(19))
def da():
d0 = collections.deque()
for i in range(100):
d0.append(L)
@qlife
qlife / TTSS.txt
Created July 26, 2018 03:14
Quotes from "Tinker Tailor Soldier Spy"
Instead of that Scottish twerp. Bill rebuilding Camelot' -
her fairy-talesmileagain - 'and George-'
'George picking up the bits,' said Smiley, vamping for
her,and they laughed, Smiley falsely.
'Give me a kiss, George. Give Connie a kiss.'
-- John le Carré
@qlife
qlife / config
Created July 19, 2018 01:32
ssh_config
# SSH Client
# ~/.ssh/config
Host gateway
HostName gateway.non-exist
User qlife
ForwardAgent no
Compression yes
UseKeychain yes # MacOSX specific - to use osx keychain
IdentityFile ~/.ssh/__private__key__
@qlife
qlife / faster.cpp
Created June 26, 2018 15:38
100 SameTree - both with 'old driver tricks'
/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode(int x) : val(x), left(NULL), right(NULL) {}
* };
*/
static int __initialSetup = []()
class TreeNode:
def __init__(self, val, left=None, right=None):
self.val = val
self.left = left
self.right = right
def __repr__(self):
return 'TreeNode({})'.format(self.val)
def deserialize(string):
if string == '{}':
@qlife
qlife / gen_uuid4.sh
Created March 14, 2018 06:54
Generate UUID4 ver. 2
echo "import uuid; print str(uuid.uuid4()).lower()" | python2.7 -
@qlife
qlife / gen_uuid4.sh
Created March 14, 2018 06:53
Generate UUID ver. 1
#!/bin/sh
uuidgen | tr '[:upper:]' '[:lower:]'