Skip to content

Instantly share code, notes, and snippets.

View mutoo's full-sized avatar

Lingjia Liu mutoo

View GitHub Profile
@mutoo
mutoo / default.custom.yaml
Last active February 8, 2020 13:50
my squirrel custom patches, using wubi_pinyin
# Rime default settings
# encoding: utf-8
patch:
schema_list:
- schema: wubi_pinyin
switcher/caption: $
menu:
page_size: 5
function f(s, n, i) {
if (n == 0) return s + "<br/>";
else {
var p = (s == "") ? n + "=" : s + "+";
var m = (s == "") ? n - 1 : n;
var r = "";
for (var j = i; j <= m; j++)
r += f(p + j, n - j, j);
return r;
}
function printDigit(n) {
document.write(n);
}
function printOut(n) {
if (n >= 10)
printOut(parseInt(n / 10));
printDigit(n % 10);
}
class IntCell
{
public:
explicit IntCell(int initialValue = 0)
:storedValue(initialValue) {}
int read() const {return storedValue;}
void write(int x) {storedValue = x;}
private:
@mutoo
mutoo / n_largest_number_bubble.js
Last active December 17, 2015 21:29
a simple implement of bubble sort to find the n-largest number
var N = 1000;
var arr = [];
for (var i = 0; i < N; i++)
arr.push(Math.random() * N);
var target = parseInt(N / 2);
function bubbleSort(arr) {
for (var i = 1; i < N; i++) { // do N-1 times
for (var j = 0; j < N - i; j++) {
@mutoo
mutoo / count1InBin.js
Created May 30, 2013 03:53
use recursion to count "1" in number as binary
function count1InBin(n){
if(n<2)
return n&1;
return count1InBin(n>>1)+(n&1); // note: +'s priority is higher than &
}
console.log(count1InBin(0)); // output: 0
console.log(count1InBin(1)); // output: 1
console.log(count1InBin(2)); // output: 1
console.log(count1InBin(3)); // output: 2
@mutoo
mutoo / min_max_without_if.js
Created May 30, 2013 05:50
min(a,b) and max(a,b) without ‘if statement’ in javascript
function min(a,b) {return a<b&&a||b;}
function max(a,b) {return a>b&&a||b;}
wget http://pypi.python.org/packages/source/p/pyOpenSSL/pyOpenSSL-0.13.tar.gz && tar zxvf pyOpenSSL-0.13.tar.gz && cd pyOpenSSL-0.13 && sudo python3 setup.py install
function maxSubSum(arr) {
var maxSum = 0, thisSum = 0;
for (i = 0; i < arr.length; i++) {
thisSum += arr[i];
if (thisSum > maxSum)
maxSum = thisSum;
else if (thisSum < 0)
thisSum = 0;
}
return maxSum;
Function.prototype.before = function(func){
var __self =this;
return function(){
var ret = func.apply(this, arguments);
if(ret===false){
return false;
}
__self.apply(this, arguments);
return ret;
}