Skip to content

Instantly share code, notes, and snippets.

@iamso1
iamso1 / logFunc.js
Last active September 19, 2018 03:44
log function info
function logFunc(func){
console.log(`[${func.name}] has been excute`);
func.exec=function(...param){
try{
console.log(`param is`, param);
const start=Date.now();
console.log(`start at`,start);
const execResult= func(param);
@iamso1
iamso1 / groupby.js
Created August 27, 2018 18:56
groupby
const groupBy = function(xs, key) {
return xs.reduce(function(rv, x) {
(rv[x[key]] = rv[x[key]] || []).push(x);
return rv;
}, {});
};
//usage:
const data =[{id:1, v:1},{id:1, v:2},{id:3, v:1}]
const result= groupBy(data, 'id');
@iamso1
iamso1 / crack-twich-clip.js
Last active May 17, 2018 11:49
crack-twich-clip block download
/*
* 使用方法
* step 1: 新增一個書籤(隨便位置都可以)
* step 2: 編輯書籤的資訊
* step 3: 複製下面的程式碼, 貼到網址列裡面後儲存
* step 4: 開啟clip後, 點選剛剛你新增的書籤, 接著再對影片點右鍵, 就可以直接下載了
*/
javascript:(()=>{
document.querySelector('.player-overlay').className='media'
@iamso1
iamso1 / screen.js
Last active February 11, 2018 13:38
reactNative-navigator
import React, { Component } from 'react';
import { View, Text, Image, TouchableOpacity, Dimensions } from 'react-native';
const Width = Dimensions.get('window').width;
const Height = Dimensions.get('window').height;
export default class FirstTabScreen extends Component {
constructor(props) {
super(props);
this.props.navigator.setOnNavigatorEvent(this.onNavigatorEvent.bind(this));
this.state = {};
}
@iamso1
iamso1 / note.md
Created September 14, 2017 16:47
[Quokka] 各種小密技
  1. 重新啟動quokka的即時運算 按F1 並輸入 Quokka.js start on current file 就可以重新執行當前檔案

  2. 計算程式執行時間

//在要計算的程式後面加上 /*?.*/ 就會顯示當下執行的時間
let num=Math.floor(Math.random()*100);/*?.*/
@iamso1
iamso1 / comparator.js
Last active September 5, 2017 17:02
[Ramda] comparator 之謎, 如何判斷兩個參數大小 ( 以0,1,-1表示)
module.exports = _curry1(function comparator(pred) {
return function(a, b) {
return pred(a, b) ? -1 : pred(b, a) ? 1 : 0;
};
});
@iamso1
iamso1 / comparator.js
Created September 5, 2017 17:00
[Ramda] comparator
module.exports = _curry1(function comparator(pred) {
return function(a, b) {
return pred(a, b) ? -1 : pred(b, a) ? 1 : 0;
};
});
@iamso1
iamso1 / sample.js
Last active September 14, 2017 16:23
[Selenium WebDriver] solve NoSuchElementError
//排除前端頁面物件動態生成 造成後端爬蟲無法正確抓到內容的錯誤
driver.get('http://grbsearch.stpi.narl.org.tw/search/planDetail?id=2228&docId=35');
driver.wait(until.elementLocated(By.id('maincontent')),5000).then(()=>{
driver.getPageSource().then(body => {
const $ = cheerio.load(body);
console.log($('#maincontent'));
});
});