Skip to content

Instantly share code, notes, and snippets.

@1000ch
1000ch / pre-commit.sh
Last active October 25, 2016 06:38 — forked from arnaud-lb/pre-commit.sh
pre-commit git hook for crushing images
#!/bin/sh
# to use, save this file as .git/hooks/pre-commit in your git repo
# make sure to add execute permissions using: chmod +x .git/hooks/pre-commit
command -v imgo >/dev/null 2>&1 || {
echo "\033[1mPlease install imgo to reduce images size before commit\033[0m"
echo "Install imgo with the following:"
echo "\t \033[1mnpm install -g imgo\033[0m"
exit 1;
}
#!/bin/node
// via http://starwing.net/suddenly_death.html
function getByteLength (string) {
var r = 0;
for (var i = 0; i < string.length; i++) {
var c = string.charCodeAt(i);
// Shift_JIS: 0x0 ~ 0x80, 0xa0 , 0xa1 ~ 0xdf , 0xfd ~ 0xff
// Unicode : 0x0 ~ 0x80, 0xf8f0, 0xff61 ~ 0xff9f, 0xf8f1 ~ 0xf8f3