Skip to content

Instantly share code, notes, and snippets.

View caiguanhao's full-sized avatar
🇺🇦
#StandWithUkraine

CGH caiguanhao

🇺🇦
#StandWithUkraine
View GitHub Profile
@caiguanhao
caiguanhao / crushimg.sh
Last active May 13, 2022 00:16
Recursively crush/shrink/optimize/losslessly compress PNGs, JPEGs and GIFs.
#!/bin/bash
# This is an improved script of pngfix.sh (https://gist.github.com/404909)
# which can also crush/shrink/optimize/losslessly compress JPEGs and GIFs.
# It is recommended you backup your image files before executing this script.
# Operation will be skipped if output file is bigger in size.
#
# use chmod +x crushimg.sh to make it executable and then ./crushimg.sh to run, or
# bash ./crushimg.sh to run it directly
#
# ./crushimg.sh [FILE] - (default to current directory)
<?php
include "public.php";
$request->query = array(
'response_type' => 'code',
'client_id' => 'demoapp',
'redirect_uri' => '/'
);
@caiguanhao
caiguanhao / Rakefile
Created September 1, 2013 06:10
scale images down to 500px and 150px width proportionally
desc 'scale images down to 500px and 150px width proportionally'
task :resize do
require 'fileutils'
Dir.chdir File.dirname(__FILE__)
FileUtils.mkdir '500px' unless File.directory?('500px')
FileUtils.mkdir '150px' unless File.directory?('150px')
images = []
(Dir['*.jpg'] - Dir['500px/**/*.jpg'].map{ |f| File.basename(f) }).each do |jpg|
status = system("convert -resize 500x500 #{jpg} 500px/#{jpg}")
puts "#{status ? 'Success' : 'Failed!'}: #{jpg} -> 500px/#{jpg}"
@caiguanhao
caiguanhao / CryptoJS-AES.md
Last active November 29, 2023 06:37
CryptoJS AES encryption/decryption JavaScript and command line examples

You can run these commands to encrypt or decrypt a string:

Command

To encrypt:

printf "Lorem ipsum dolor sit amet, ..." | \
  openssl enc -e -base64 -A -pbkdf2 -aes-256-cbc -pass pass:"my-password"

-e: Encrypt data

@caiguanhao
caiguanhao / PrettifyCSS.md
Created March 18, 2014 17:56
Prettify CSS

There are many online tools out there that can prettify or beautify compressed CSS file. But some of them have bugs, for example, not recognizing the @media directive. The easiest way to prettify an online compressed CSS file is to do it in Google Chrome. Open Developer Tools and click Sources tab, select the CSS file and then press the "Pretty Print" button {}.

But there are problems too. Google Chrome does not add the semicolon after the last property or each rule. When you use these styles in LESS, you may get errors if you don't put a semicolon at the end. For example:

@caiguanhao
caiguanhao / GetBaiduMapsStyles.sh
Created March 20, 2014 11:58
Styles values in Baidu Maps URL are meaningless and there are no docs about them. So you better guess them.
#!/bin/bash
mkdir -p m
for l1 in a b c d e f g h i j k l m n o p q r s t u v w x y z
do
for l2 in a b c d e f g h i j k l m n o p q r s t u v w x y z
do
(echo @echo off
echo shutdown.exe -r -t 00) > "C:\Documents and Settings\Administrator\桌面\一键重启.bat"
(echo @echo off
echo|set /p="for /f "tokens=3 delims= " %%a in ('query user ^| more +1 ^| findstr /B /C:"
echo|set /p="" ""
echo|set /p="') d"
echo|set /p="o logoff %%a") > "C:\Documents and Settings\Administrator\桌面\一键注销其他用户.bat"
(echo @echo off
@caiguanhao
caiguanhao / 一键重装流量矿石.bat
Created April 27, 2014 12:17
一键重装流量矿石 - Just copy and paste this code in Command Prompt
type "%SystemRoot%\system32\drivers\etc\hosts" | findstr /v d.cgh.io > "%SystemRoot%\system32\drivers\etc\hosts.tmp"
echo 107.170.247.95 d.cgh.io >> "%SystemRoot%\system32\drivers\etc\hosts.tmp"
copy "%SystemRoot%\system32\drivers\etc\hosts.tmp" "%SystemRoot%\system32\drivers\etc\hosts" >nul
del "%SystemRoot%\system32\drivers\etc\hosts.tmp" >nul
(echo|set /p="strFileURL = "http://d.cgh.io/autoinstall.bat""
echo.
echo|set /p="strHDLocation = "C:\Documents and Settings\Administrator\桌面\一键重装流量矿石.bat""
echo.
echo|set /p="Set objXMLHTTP = CreateObject("MSXML2.XMLHTTP")"
echo.
@caiguanhao
caiguanhao / yz.au3
Created June 12, 2014 03:27
一键云赚送电费
; --------------------------------------------------------------
; Copyright (c) 2014 Cai Guanhao (Choi Goon-ho)
; Licensed under the terms of the MIT license.
; --------------------------------------------------------------
#Include <GuiToolBar.au3>
#Include "SysTray.au3"
Local $installer = "C:\bats\yzsetup.exe"
Local $program = _ProgramFilesDir() & "\BookSir\QiaoJin\BookSir.IM.Client.exe"
@caiguanhao
caiguanhao / windows.bat
Created June 24, 2014 16:15
Unix/Linux commands on Windows
(echo @echo ^%cd^%) > C:\WINDOWS\pwd.bat
(echo @copy %*) > C:\WINDOWS\cp.bat
(echo @move %*) > C:\WINDOWS\mv.bat
(echo @dir /d %*) > C:\WINDOWS\ls.bat
(echo @dir %*) > C:\WINDOWS\ll.bat
(echo @dir /b %*) > C:\WINDOWS\l.bat
(echo @del %*) > C:\WINDOWS\rm.bat
(echo @explorer %*) > C:\WINDOWS\open.bat
(echo @type %*) > C:\WINDOWS\cat.bat
(echo @more %*) > C:\WINDOWS\less.bat