Skip to content

Instantly share code, notes, and snippets.

@gaoxiaoliangz
gaoxiaoliangz / Mac OS X: Open in Visual Studio Code
Last active November 22, 2019 03:42 — forked from tonysneed/Mac OS X: Open in Visual Studio Code
Add a command to Finder services in Mac OSX to open a folder in VS Code
- Open Automator
- File -> New -> Quick Action
- Change "Service Receives" to "files or folders" in "Finder"
- Add a "Run Shell Script" action
- Change "Pass input" to "as arguments"
- Paste the following in the shell script box: open -n -b "com.microsoft.VSCode" --args "$*"
- Save it as something like "Open in Visual Studio Code"
const toVSCodeSnippetBody = string =>
string
.split('\n')
.map(line => {
const chars = Array.from(line)
if (chars.length === 0) {
return '"",'
}
let newChars = []
chars.forEach((char, idx) => {
@gaoxiaoliangz
gaoxiaoliangz / generate-pushid.js
Created March 13, 2018 14:56 — forked from mikelehen/generate-pushid.js
JavaScript code for generating Firebase Push IDs
/**
* Fancy ID generator that creates 20-character string identifiers with the following properties:
*
* 1. They're based on timestamp so that they sort *after* any existing ids.
* 2. They contain 72-bits of random data after the timestamp so that IDs won't collide with other clients' IDs.
* 3. They sort *lexicographically* (so the timestamp is converted to characters that will sort properly).
* 4. They're monotonically increasing. Even if you generate more than one in the same timestamp, the
* latter ones will sort after the former ones. We do this by using the previous random bits
* but "incrementing" them by 1 (only in the case of a timestamp collision).
*/
@gaoxiaoliangz
gaoxiaoliangz / IndexedDB101.js
Created March 3, 2018 07:40 — forked from JamesMessinger/IndexedDB101.js
Very Simple IndexedDB Example
// This works on all devices/browsers, and uses IndexedDBShim as a final fallback
var indexedDB = window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB || window.shimIndexedDB;
// Open (or create) the database
var open = indexedDB.open("MyDatabase", 1);
// Create the schema
open.onupgradeneeded = function() {
var db = open.result;
var store = db.createObjectStore("MyObjectStore", {keyPath: "id"});
// http://www.codewars.com/kata/japanese-style-emoticons-decoder/solutions/javascript?show-solutions=1
const jsStr = require('./min')
// console.log(jsStr)
// function decode(str) {
// // var s = str.slice(0, str.length - 2)
// return eval(str)
function toTime(secs) {
const s = secs % 60
const m = (secs - s) / 60
return [(m - (m % 60)) / 60, m % 60, s]
}
function test() {
const tests = [8654, 0, 10, 600, 60, 987678987, 61]
tests.forEach(time => {
@gaoxiaoliangz
gaoxiaoliangz / mathjax-demo.html
Created December 4, 2017 14:51
mathjax example
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="initial-scale=1, viewport-fit=cover">
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
showProcessingMessages: false,
tex2jax: {
@gaoxiaoliangz
gaoxiaoliangz / iterm2-solarized.md
Created December 3, 2017 10:43 — forked from kevin-smets/iterm2-solarized.md
iTerm2 + Oh My Zsh + Solarized color scheme + Meslo powerline font + [Powerlevel9k] - (macOS)

Default

Default

Powerlevel9k

Powerlevel9k

class Observable {
constructor(connector) {
this.connector = connector
this.observer = {
onNext: (val) => {
if (this.handler) {
this.handler(val)
}
},
var x1 = 'aaaaa\nbbbb\ncccc\n\nddd'
var y1 = ''
for (let i = 0; i < 100000; i++) {
y1 = y1 + x1
}
const markAll = () => {
const t0 = new Date().valueOf()
marked(y1, {
gfm: true,