Skip to content

Instantly share code, notes, and snippets.

View kyktommy's full-sized avatar
🎯
Focusing

kyktommy kyktommy

🎯
Focusing
View GitHub Profile
@kyktommy
kyktommy / fast.js
Created June 12, 2020 04:50
faster javascript methods
// remove from array, no seq
// https://jsperf.com/array-remove-by-index
var arr = [1,2,3]
var index = arr.indexOf(2)
arr[index] = arr[arr.length - 1]
arr.pop()
@kyktommy
kyktommy / eruda.js
Last active May 1, 2020 14:42
eruda script
/**
1. bookmark any page in mobile
2. edit bookmark into below js as "eruda"
3. go to desired debug page
4. url bar tap "erude" and click the bookmarked link
*/
javascript:(function () { var script = document.createElement('script'); script.src="//cdn.jsdelivr.net/npm/eruda"; document.body.appendChild(script); script.onload = function () { eruda.init() } })();
@kyktommy
kyktommy / youtube-dl.sh
Last active April 11, 2020 16:01
youtube-dl helper
# download as mp4, playlist also
function youtube-dl-mp4() {
youtube-dl -f "[height <=? 720][tbr>500]" --yes-playlist $1
}
# download as mp3
function youtube-dl-mp3() {
youtube-dl -x --audio-format mp3 --add-metadata $1
}
@kyktommy
kyktommy / git-helper.sh
Last active September 9, 2020 03:53
git helper
# pull latest with stash
function gitup() {
git stash -u
git pull --rebase
git stash pop
}
# stash staged
function gitstash() {
git stash push -m $1 -- $(git diff --staged --name-only)
@kyktommy
kyktommy / screencap-jpg.sh
Last active April 7, 2020 03:09
helpful mac settings
# save disk space, screen no need png
defaults write com.apple.screencapture type jpg;killall SystemUIServer
@kyktommy
kyktommy / httplog.go
Last active December 31, 2019 11:21
httplog.go
package main
import (
"bytes"
"fmt"
"io"
"io/ioutil"
"net/http"
"strings"
)
@kyktommy
kyktommy / findgo.sh
Last active December 31, 2019 03:44
find project in gopath
function findgo() {
find $GOPATH/src -mindepth 3 -maxdepth 3 -type d -exec ls -ld "{}" \; | grep $1 | awk '{ print $9 }' | nl
}
findgo gogo
function cdgo() {
r=$(findgo $1)
echo $r
printf 'cd to ? > '
@kyktommy
kyktommy / dropbox.go
Created March 11, 2019 07:22
golang dropbox upload
package dropbox
import (
"bytes"
"encoding/json"
"errors"
"io/ioutil"
"log"
"net/http"
)
@kyktommy
kyktommy / safari-bookmarket.js
Created May 17, 2015 03:25
safari book testerrrr
javascript:(function(){if(!($=window.jQuery)){script=document.createElement("script");script.src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js";script.onload=a;document.body.appendChild(script)}else{a()}function a(){var b=function(){var e="";for(var d=0;d<32;d++){e+=Math.floor(Math.random()*15).toString(15)}return e.substr(0,15)};var c=$("#registration-form");c.find("#id_first_name").val(b());c.find("#id_last_name").val(b());c.find("#id_email").val(b()+"@gmail.com");c.find("#id_username").val(b());c.find("#id_password1").val(b());c.find("#id_legal").attr("checked",true);c.submit()}})();
@kyktommy
kyktommy / query
Last active August 29, 2015 14:06
Neo4j query examples
MATCH (b:Book)
WHERE ANY ( tag IN b.tags WHERE tag IN ['nosql','neo4j'] )
RETURN b.title,b.tags
SKIP 20
ORDER BY b.title DESC
LIMIT 20
------------
MATCH (b:Book)<-[r:Votes]-(:User)