Skip to content

Instantly share code, notes, and snippets.

@YuMS
YuMS / android_ndk_thread_affinity.cpp
Last active May 31, 2022 16:15
Should work on armv7 as well as armv8
#include <sys/syscall.h>
#include <sys/types.h>
#include <pthread.h>
#include <unistd.h>
#include <errno.h>
#include <cstdio>
#ifndef CPU_SETSIZE
#define CPU_SETSIZE 1024
@YuMS
YuMS / update-git.sh
Created June 29, 2016 09:28
Update git to latest version on Ubuntu
#!/bin/bash
sudo add-apt-repository -y ppa:git-core/ppa
sudo apt-get update
sudo apt-get install git -y
# NOTE: If you are using Ubuntu Precise or Debian Wheezy, you might want to read about running Node.js >= 4.x on older distros.
curl -sL https://deb.nodesource.com/setup_4.x | sudo -E bash -
sudo apt-get install -y nodejs
# Alternatively, for Node.js v6:
curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -
sudo apt-get install -y nodejs
@YuMS
YuMS / .xmodmap
Created June 29, 2016 08:31
Put this inside ~/.xmodmap file, and run `xmodmap ~/.xmodmap`
!
! Swap Caps_Lock and Control_L
!
remove Lock = Caps_Lock
remove Control = Contol_L
keysym Control_L = Caps_Lock
keysym Caps_Lock = Control_L
add Lock = Caps_Lock
add Control = Control_L
#!/bin/bash
sudo add-apt-repository -y ppa:ubuntu-elisp
sudo apt-get update
sudo apt-get install vim-athena emacs-snapshot git -y
git clone https://github.com/syl20bnr/spacemacs ~/.emacs.d
curl https://j.mp/spf13-vim3 -L > spf13-vim.sh && sh spf13-vim.sh
git clone https://github.com/YuMS/vimrc.git ~/GitHub/vimrc/
cd ~/GitHub/vimrc
bash setup.sh &
emacs &
@YuMS
YuMS / CartPole-v0.py
Created May 19, 2016 16:00 — forked from JKCooper2/CartPole-v0.py
[Open AI| CartPole v0 - Simulated Annealing v0
import logging
import gym
from SimulatedAnnealing import SimulatedAnnealingAgent
def main():
logger = logging.getLogger()
logger.setLevel(logging.DEBUG)
env = gym.make('CartPole-v0')
@YuMS
YuMS / retryUntilSuccess.js
Created January 27, 2016 09:18
generate a promise that keep invoking another promise generator until it succeed
function retryUntilSuccess(promiseFunc, args, timeout = 1000, retry = -1) {
return new Promise((resolve, reject) => {
const tryForTimes = (attempts) => {
promiseFunc(...args).then((result) => {
resolve(result);
}).catch((err) => {
if (attempts === 0) {
reject(err);
} else {
setTimeout(() => tryForTimes(attempts - 1), timeout);