Skip to content

Instantly share code, notes, and snippets.

View shaoshing's full-sized avatar

Shaoshing Li shaoshing

View GitHub Profile
@shaoshing
shaoshing / number2txt for SuperMemo
Last active August 2, 2022 20:43
Ruby script to convert Numbers file to txt, so that it can be imported into Supermemo.
#!/usr/bin/env ruby
#
# Usages
# num2txt path/to/your/file.numbers
require 'csv'
if !ARGV[0]
puts "Please specify a number file."
@shaoshing
shaoshing / clone.sh
Created May 24, 2018 01:19
Clone all private github repos
TOKEN="[PERSONAL-ACCESS-TOKEN]"
curl -u "$TOKEN:x-oauth-basic" -s https://api.github.com/user/repos?visibility=private |
awk '/ssh_url/ {print $2}' |
sed 's/[\"\,]//g' |
xargs -L1 git clone
@shaoshing
shaoshing / 1587677649.txt
Created April 23, 2020 21:34
Created with Copy to Gist
/**
* @param {number[][]} intervals
* @return {number[]}
*/
var findRightInterval = function(intervals) {
// collecting and sort tne ends with their index
const starts = intervals.map(([start], index) => ({ start, index })).sort((a, b) => a.start - b.start)
return intervals.map(([_, end]) => {
const startIndex = findMinimumStart(starts, end)
@shaoshing
shaoshing / test.js
Created November 6, 2018 00:05
Nodejs event loop: setTimeout v.s. setImmediate v.s. process.nextTick
const fs = require("fs");
// The execution order of the setTimeout and setImmedate callbacks are non-deterministic.
setTimeout(() => {
console.info("setTimeout in main");
}, 0);
setImmediate(() => {
console.info("setImmediate in main");
var HIGH_PRI = 'is%3Aopen+is%3Aissue+label%3A%22High+Pri%22',
MEDIUM_PRI = 'is%3Aopen+is%3Aissue+label%3A%22Medium+Pri%22',
LOW_PRI = 'is%3Aopen+is%3Aissue+label%3A%22Low+Pri%22',
documentID = 'GOOGLE_DOCUMENT_ID';
function getIssueCount(query, open) {
var page = UrlFetchApp.fetch('https://github.com/adobe-photoshop/spaces-design/issues?q=' + query),
content = page.getContentText(),
console.time("documentID");
_spaces.ps.descriptor.get({
"_multiGetRef": [
{
"_propertyList": [
"documentID"
]
},
{
"_range": "document",
@shaoshing
shaoshing / Gemfile
Created January 16, 2014 17:26
Using ActiveRecord in jRuby
source "https://rubygems.org"
gem 'activerecord', '~> 3.2.14'
gem 'activerecord-jdbcmysql-adapter', :platform => :jruby
@shaoshing
shaoshing / Number2Txt for Flashcard Deluxe
Last active December 11, 2015 17:29
Shell script to convert Numbers file to txt that could imported to Flashcard Deluxe (an iOS app)
#!/bin/bash
#
# Usage:
# convert.sh ~/Downloads/Cards.numbers
# (must specify full path)
#
# AppleScript to convert from numbers to csv
osascript -e '
on run argv
{
"name": "transform",
"descriptor": {
"null": {
"_ref": [
{
"_ref": "layer",
"_id": 19
},
{
batchPlay: ([
{
"name": "select",
"descriptor": {
"null": {
"_ref": [
{
"_ref": "layer",
"_id": 7
},