Skip to content

Instantly share code, notes, and snippets.

View thstarshine's full-sized avatar
🏔️

starshine thstarshine

🏔️
  • Taipei, Taiwan
View GitHub Profile
console.log(angular);
@thstarshine
thstarshine / gist:7df5cd021a8d0b9c5976
Last active December 17, 2015 16:36
mongoose w/ bluebird promise performance test
mongoose schema:
update: function(row){
return this.update({}, row).exec();
}
// method 1
batchUpdate: function(rows){
return Promise.map(rows, function(row){
return self.update({}, row).exec();
@thstarshine
thstarshine / cards.js
Last active October 20, 2017 15:06
cards
const puppeteer = require('puppeteer');
(async () => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto('https://www.fugle.tw/picture/cards?cards[]={"c":"FCRD000002","s":"2330"}');
await page.waitForSelector('line.candle-stem');
await page.addScriptTag({
content: `
d3.selectAll(".candleRect").each(function(d,i){
@thstarshine
thstarshine / replace.sh
Created October 21, 2017 09:40
replace ssh authorized_keys by sed
#!/bin/bash
export NEW_SSH_KEY=ssh-rsa\ ....\ user@host
sed -e "s#ssh-rsa.*OLD_KEY_ID#$NEW_SSH_KEY#" ~/.ssh/authorized_keys
# ssh root@host 'bash -s' < this_script.sh
// ==UserScript==
// @name New Userscript
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author You
// @match https://www.fugle.tw/picture/cards?cards[]={%22c%22:%22FCRD000002%22,%22s%22:%222330%22}
// @grant none
// ==/UserScript==
@thstarshine
thstarshine / mongodb_collection_sizes.js
Created December 28, 2017 08:00 — forked from joeyAghion/mongodb_collection_sizes.js
List mongodb collections in descending order of size. Helpful for finding largest collections. First number is "size," second is "storageSize."
var collectionNames = db.getCollectionNames(), stats = [];
collectionNames.forEach(function (n) { stats.push(db[n].stats()); });
stats = stats.sort(function(a, b) { return b['size'] - a['size']; });
for (var c in stats) { print(stats[c]['ns'] + ": " + stats[c]['size'] + " (" + stats[c]['storageSize'] + ")"); }
@thstarshine
thstarshine / crawler.vba
Last active July 14, 2018 07:36
Crawl website by Excel VBA
' # Show developer tab in Excel:
' https://spreadsheeto.com/developer-tab/
' # This vba example opens IE with finance.yahoo.com website, auto clicks "Quarterly" button, and then copies all td values
' of financial report into "Sheet1" sheet.
' # Can possibly use HTTP Request alternatively: http://excelerator.solutions/2017/08/28/excel-http-get-request/ (instead of open ie)
Sub test()
Dim RowCount As Integer
Dim sht As Worksheet
@thstarshine
thstarshine / encrypt_decrypt_example.js
Created October 29, 2018 08:14 — forked from erans/encrypt_decrypt_example.js
Example of encryption and decryption in node.js
var crypto = require("crypto")
function encrypt(key, data) {
var cipher = crypto.createCipher('aes-256-cbc', key);
var crypted = cipher.update(text, 'utf-8', 'hex');
crypted += cipher.final('hex');
return crypted;
}
@thstarshine
thstarshine / test.sh
Last active June 26, 2019 01:37
shell script exec string command
#!/bin/bash
# /tmp/cmd = -l
a='$(cat /tmp/cmd)'
echo "ls $a" # => ls $(cat /tmp/cmd)
# alternatives to:
#eval ls $a
{
"openapi" : "3.0.0",
"info" : {
"title" : "Taiwan Stock Market Real-time Quotes API",
"description" : "### 相關說明:\n* 所有日期格式(date, time)皆以 ISO 8601 格式傳輸及實作 \n* 回傳格式參照 google json guide \n* 所有 Success Response 包含 apiVersion, { data: { info: {}}} \n* 所有 Error Response property code 同 http status code \n* 所有 Error Response Format 相同\n",
"contact" : {
"email" : "development@fugle.tw"
},
"license" : {
"name" : "Apache 2.0",