Skip to content

Instantly share code, notes, and snippets.

View yuler's full-sized avatar
🎯
Focusing

Yu Le yuler

🎯
Focusing
View GitHub Profile
@yuler
yuler / crawl.sh
Last active October 31, 2024 10:38
A bash for fetch exercism.org
#!/usr/bin/env bash
WORKSPACE=$HOME/Exercism/ruby
TRACK=ruby
EXTENSION=rb
cd "$WORKSPACE" || exit
# Get exercise name
if [ -n "$1" ]; then
name="$1"

Setup RuboCop

Install

gem install rubocop
rubocop --version
rubocop <file.rb> --autocorrect
@yuler
yuler / current_helpers.js
Created March 2, 2024 15:05
On-demand JavaScript objects from current HTML <meta> elements
// Origin from Basecamp app.hey.com
// refs: https://app.hey.com/assets/helpers/current_helpers-69434f7688aaf68b68226df19cd29426713fdcad.js
// refs: https://github.com/marcoroth/current.js
/**
* On-demand JavaScript objects from "current" HTML <meta> elements
*
* @example
* ```html
* <meta name="current-identity-id" content="123">
@yuler
yuler / ECMAScript-versions.md
Created December 15, 2021 01:43
The ECAMScript versions

ECMAScript versions

从 ES6 版本被重命名为 ES2015 开始,后续的版本开始按照 release 的年份来命名。

ECMAScript wiki

对照表

Old Edition New Edition
@yuler
yuler / dedent.js
Created November 28, 2021 09:47
Remove indent
function dedent(str) {
str = str.replace(/\r?\n/g, '\n')
let arr = str.match(/^[ \t]*(?=\S)/gm)
let i = 0,
min = 1 / 0,
len = (arr || []).length
for (; i < len; i++) min = Math.min(min, arr[i].length)
return len && min
? str.replace(new RegExp(`^[ \\t]{${min}}`, 'gm'), '')
: str
@yuler
yuler / 01_render.html
Created April 25, 2021 13:26
Learn Vue
<div id="app"></div>
<style>
.red {
color: red;
}
</style>
<script>
function h(tag, props, children) {
@yuler
yuler / number-to-chinese.ts
Created April 18, 2021 16:36
Number to Chinese
/**
* Translate number to chinese word
* @param num number
*/
const digits = ['零', '一', '二', '三', '四', '五', '六', '七', '八', '九']
const units = ['', '十', '百', '千', '万', '亿']
const point = '点'
@yuler
yuler / hash.js
Created April 12, 2021 12:49
Javascript implementation of Java’s String.hashCode() method
/**
* Javascript implementation of Java’s String.hashCode() method
* refs: https://werxltd.com/wp/2010/05/13/javascript-implementation-of-javas-string-hashcode-method
* refs: https://docs.oracle.com/javase/8/docs/api/java/lang/String.html#hashCode--
*
* Returns a hash code for a string.
* @param str string
* @return number
*/
function hash(str) {
# Install main function
install() {
# variables
shadowsocks_passwd="pwd"
shadowsocks_method="aes-256-cfb"
shadowsocks_port="9001"
fast_open="true"
# config
cat > ~/shadowsocks.json<<-EOF