Skip to content

Instantly share code, notes, and snippets.

View joujiahe's full-sized avatar

Johnson Chou joujiahe

View GitHub Profile
@joujiahe
joujiahe / pdfimage
Created October 12, 2020 15:46 — forked from innermond/pdfimage
Extract images from pdf but, surprise! The images that contain alpha channels are extracted as two images. The source and the mask, as they are stored inside pdf file. This script recombine them into an one png file with given transparency
#/usr/bin/bash
# extract images from pdf at first-hand
#prefix=pict
#echo extract images from "$1"
#pdfimages -j "$1" $prefix
# IMAGES ARE SAVED SECVENTIALLY AS IMAGE AND THE NEXT IS A MASK IMAGE !!!!
declare -a files=($(ls *.ppm *.pbm))
mask=
image=
for (( i = 0; i < ${#files[*]}; i = i + 2 ))
@joujiahe
joujiahe / bash
Created February 23, 2019 06:04
Replace DOS line endings to Unix style in MacOS
// to get ^M, type CTRL-V and CTRL-M
find . -type f -name '*.ts' -exec perl -p -i -e "s/^M//g" {} \;
@joujiahe
joujiahe / idbkeyrange_forprefix.js
Created July 20, 2018 01:56 — forked from inexorabletash/idbkeyrange_forprefix.js
Helper for creating an IDBKeyRange for all keys with a given prefix
// Basic p(r)olyfill for proposed feature
// This defines no successor of empty arrays, so the range for prefix
// [] or [[],[]] has no upper bound.
// An alternate definition would preclude adding additional nesting,
// so the range for prefix [] would have upper bound [[]] and the
// range for prefix [[], []] would have upper bound [[], [[]]].
IDBKeyRange.forPrefix = function(prefix) {
// Ensure prefix is a valid key itself:
@joujiahe
joujiahe / url_to_drive.js
Created November 7, 2017 10:32 — forked from denilsonsa/url_to_drive.js
Google Apps Script to upload a file from an URL directly to Google Drive.
// url_to_drive.gs
// Google Apps Script
// Allows uploading a URL directly to Google Drive.
//
// Live link:
// https://script.google.com/macros/s/AKfycbzvhbHS4hnWPVBDHjQzZHA0qWq0GR-6hY7TbYsNto6hZ0MeAFZt/exec
//
// Source-code:
// https://gist.github.com/denilsonsa/8134679
// https://script.google.com/d/1Ye-OEn1bDPcmeKSe4gb0YSK83RPMc4sZJt79SRt-GRY653gm2qVUptoE/edit
@joujiahe
joujiahe / gitflow-breakdown.md
Created June 15, 2016 04:01 — forked from JamesMGreene/gitflow-breakdown.md
A comparison of using `git flow` commands versus raw `git` commands.

Initialize

gitflow git
git flow init git init
git commit --allow-empty -m "Initial commit"
git checkout -b develop master

Connect to the remote repository

@joujiahe
joujiahe / catch-any-error.js
Created May 12, 2016 05:42
Catch all error in browser
(function(){
/**
* Capture error data for debugging in web console.
*/
var captures = [];
/**
* Wait until `window.onload`, so any external scripts
@joujiahe
joujiahe / ellipsis.css
Created September 28, 2015 06:55
CSS Ellipsis
.ellipsis {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
@joujiahe
joujiahe / route.js
Created September 2, 2015 18:38
Sample of JavaScript regexp route.
function route(url, params) {
return url.replace(/:(\w+)/g, function (match, p) {
return params[p];
});
}
@joujiahe
joujiahe / zsh256colors
Last active August 29, 2015 14:11
Show zsh 256 colors
for code in {000..255}; do print -P -- "$code: %F{$code}Test%f"; done
@joujiahe
joujiahe / ie-detect.js
Created November 20, 2014 06:43
IE detection in JavaScript
function msieversion() {
var ua = window.navigator.userAgent,
msie = ua.indexOf("MSIE ");
// If IE, alert version
if (msie > 0 || !!navigator.userAgent.match(/Trident.*rv\:11\./))
alert(parseInt(ua.substring(msie + 5, ua.indexOf(".", msie))));
else
alert('otherbrowser');