Skip to content

Instantly share code, notes, and snippets.

View abcdabcd987's full-sized avatar
😄
( ´ ▽ ` )ノ

Lequn Chen abcdabcd987

😄
( ´ ▽ ` )ノ
View GitHub Profile
/*
* GET message listing => show()
* POST meaasge posting => send()
*/
var settings = require('../settings');
var group = require('../models/group');
var mesg = require('../models/mesg');
var md = require('markdown').markdown.toHTML;
#include <vector>
/**
Given an non-decreasing ordered array `arr`, search the biggest `i` that makes `arr[i] == value`.
If `i` doesn't exist, return -1
*/
int search_last_match(const std::vector<int>& arr, const int value)
{
int lef = 0, rig = static_cast<int>(arr.size());
while (rig-lef > 1)
@abcdabcd987
abcdabcd987 / calc_password.js
Created September 25, 2015 06:59
using pbkdf2 to hash password (node.js)
// See: http://stackoverflow.com/questions/17218089/salt-and-hash-using-pbkdf2
// See: https://crackstation.net/hashing-security.htm
'use strict';
let Promise = require('bluebird');
let crypto = require('crypto');
function calcPassword(password) {
const RANDOM_BYTES = 64;
@abcdabcd987
abcdabcd987 / chess_sample_ai.cc
Last active November 28, 2015 14:41
Sample AI for Programming Fall 2015
#include <ctime>
#include <cstdlib>
#include <vector>
#include <string>
#include <iostream>
#include <algorithm>
using namespace std;
const int H = 4;
const int W = 8;
def flatEnumerate(obj, prefix='root'):
if isinstance(obj, int):
return [{ prefix: obj }]
elif isinstance(obj, list):
res = []
for option in obj:
res.extend(flatEnumerate(option, prefix))
return res
elif isinstance(obj, dict):
if len(obj) == 0: return [{}]
@abcdabcd987
abcdabcd987 / TeeOutputStream.java
Created April 24, 2016 05:30
Write to multiple OutputStream
package com.abcdabcd987.compiler2016.Utility;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Arrays;
import java.util.List;
/**
* Created by abcdabcd987 on 2016-04-18.
*/
@abcdabcd987
abcdabcd987 / evalrpc_ipc_trace.ipynb
Created October 26, 2016 05:38
evalrpc_ipc_trace.ipynb
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
#include <atomic>
#include <memory>
#include <vector>
#include <thread>
#include <cstdio>
std::shared_ptr<std::vector<int>> v;
void read(const char* name) {
auto localv = std::atomic_load_explicit(&v, std::memory_order_acquire);
#!/bin/bash
# save as /root/del_user.sh
USERNAME=$1
if [[ -z "$USERNAME" ]]; then
echo "Please give me a username"
exit 1
fi
echo "This script will"
@abcdabcd987
abcdabcd987 / c2nasm.bash
Last active December 11, 2019 22:04
C to NASM Assembly
#!/bin/bash
# thanks to http://stackoverflow.com/a/20743090
# thanks to https://github.com/diogovk/c2nasm
# install objconv: https://github.com/vertis/objconv
#
# $1: source code
set -e
C_FILE="$1"
BASE_NAME="${C_FILE%.*}"