Skip to content

Instantly share code, notes, and snippets.

View livoras's full-sized avatar
🎯
Focusing

Livoras Dai livoras

🎯
Focusing
  • Guangzhou, Guangdong, China
View GitHub Profile
const nums = {
'零': 0,
'壹': 1,
'贰': 2,
'叁': 3,
'肆': 4,
'伍': 5,
'陆': 6,
'柒': 7,
'捌': 8,
import gym
from stable_baselines.common.policies import MlpPolicy
from stable_baselines.common.vec_env import SubprocVecEnv, DummyVecEnv
from stable_baselines.bench import Monitor
from stable_baselines import PPO2
from stable_baselines.results_plotter import load_results, ts2xy
import os
import numpy as np
import time
@livoras
livoras / ss.sh
Last active March 26, 2020 07:54
vultr 服务器一键安装 SS
# 先装好 ssserver
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python get-pip.py
# 本地新建配置
cat '{ \
"server": "0.0.0.0", \
"server_port": 8388, \
"local_address": "127.0.0.1", \
"local_port": 1080, \
@livoras
livoras / BCrypt.java
Created January 21, 2019 02:57 — forked from coderberry/BCrypt.java
BCrypt.java
// Copyright (c) 2006 Damien Miller <djm@mindrot.org>
//
// Permission to use, copy, modify, and distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
@livoras
livoras / MountainCar-v0-q-learning.py
Created July 22, 2018 12:08
Using Q-Learning to solve MountainCar-v0
import random
import gym
import sys
import time
import pickle
import os
env = gym.make('MountainCar-v0')
#####
@livoras
livoras / url-parse.js
Created May 3, 2017 08:14
Query string parser and manipulation.
function parseUrl (url) {
var a = document.createElement('a')
a.setAttribute('href', url)
var search = a.search
var query = {}
var kvs = search.split(/[\?&]/g)
kvs.forEach(function (kv) {
kv = kv.split('=')
if (kv.length === 2) {
query[kv[0]] = kv[1]
@livoras
livoras / DeviceUID.m
Last active August 12, 2016 07:55 — forked from miguelcma/DeviceUID.m
iOS Unique Device ID that persists between app reinstalls
/* DeviceUID.h
#import <Foundation/Foundation.h>
@interface DeviceUID : NSObject
+ (NSString *)uid;
@end
*/
// Device.m
@livoras
livoras / curry.js
Last active April 18, 2016 09:10
Simple currying function.
/**
* toArray :: ArrayLike => Array
*/
const toArray = (arrLike) => [].slice.call(arrLike, 0);
/**
* Currying a function
*/
@livoras
livoras / gena.js
Last active September 24, 2021 12:09
Genetic Algorithm in JavaScript
class Gena {
constructor(config) {
this.currentGeneration = 0
this.populations = []
this.fitnesses = []
this.mutateProbability = config.mutateProbability || 0.5 // 0 ~ 1
this.generationsSize = config.generationsSize || 100
this.populationSize = config.populationSize || 100
this.doneFitness = config.doneFitness || 1 // 0 ~ 1
@livoras
livoras / finite-state-machine.js
Last active April 27, 2023 19:54
Simplest JavaScript Finite State Machine
/**
* @param {Object} settings
* - {String} current
* - {Object} states
* - {Object} actions
* @constructor
*/
function StateMachine(settings) {
this._current = settings.initState
this.actions = settings.actions