This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.lang.invoke.MethodHandles; | |
import java.lang.invoke.VarHandle; | |
public class LockFreeQueue<E> { | |
private static final VarHandle NEXT; | |
private static final VarHandle HEAD; | |
private static final VarHandle TAIL; | |
static { | |
try { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def fork_and_wait(args, s): | |
p = subprocess.Popen(args, stdout=subprocess.PIPE) | |
def wait(): | |
time.sleep(s) | |
if p.returncode is None: | |
logging.info("kill process %s", p.pid) | |
p.kill() | |
sys.exit(1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def transform(specials, mapping, n): | |
""" | |
https://www.jinshuju.net/f/EGQL3D | |
""" | |
# rule 5 | |
if str(specials[0]) in str(n): | |
return mapping[specials[0]] | |
return ''.join(mapping[i] for i in specials if n % i == 0) or str(n) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def seg_access_log(line): | |
delimiters = {'[': ']', '"': '"'} | |
idx, start, count, delimiter, results = 0, 0, len(line), ' ', [] | |
while 1: | |
idx = line.find(delimiter, start) | |
delimiter = ' ' # reset | |
if idx < 0: | |
break |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
__author__ = 'feng' | |
articles = [ | |
'Familiarize Yourself with IntelliJ IDEA editor', | |
'While keeping the Ctrl key pressed, rotate the mouse wheel. As you rotate the mouse wheel forward', | |
'font size grows larger; as you rotate the mouse wheel backwards, font size decreases', | |
'In the popup frame, type Reset font size, and click Enter.', | |
'These operations apply to the active editor only. In the other editor tabs, font size is not affected.', | |
'There is no default keyboard shortcut associated with Reset font size action. However, you can create your', | |
'Place the caret in the editor.' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
__author__ = 'feng' | |
def is_match(patten, str): | |
match_index = 0 | |
for idx, c in enumerate(patten): | |
if c == '?': | |
match_index += 1 | |
elif c == '*': | |
if idx == len(patten) - 1: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns example | |
(:use [org.httpkit.server | |
compojure.core])) | |
(defn- handle-client-data [data] | |
(let [data (read-json data)] | |
;; routing can implented here. like socket.io's event routing | |
)) | |
;;; when streaming/polling, client post data to server, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;; http://http-kit.org | |
(ns main | |
(:use org.httpkit.server)) | |
(defn handler [req] | |
{:status 200 | |
:headers {"Content-Type" "text/plain"} | |
:body "hello world"}) | |
(run-server handler {:port 8080}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns org.httpkit.proxy-test | |
(:use [org.httpkit.server :only [run-server async-response]] | |
[org.httpkit.client :only [request]])) | |
(defn- proxy-opts [req] | |
{:url (str "http://192.168.1.101:9090" (:uri req) | |
(if-let [q (:query-string req)] | |
(str "?" q) | |
"")) | |
:timeout 30000 ;ms |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <vector> | |
using namespace std; | |
char* serialize(vector<string> &v, unsigned int *count) { | |
unsigned int total_count = 0; | |
for(int i = 0; i < v.size(); i++ ) { |
NewerOlder