Skip to content

Instantly share code, notes, and snippets.

@KevinWang15
KevinWang15 / convert.sh
Created June 24, 2024 05:13
PDF to Image Grid Conversion
# PDF to Image Grid Conversion
magick convert -density 150 "your-pdf.pdf" -alpha remove -alpha off -background white -resize 1000x page_%d.png
magick montage page_*.png -tile 3x3 -geometry 1000x+10+10 -background gray output.png
# Some fun ...
magick convert -density 150 "your-pdf.pdf" -resize 1000x page_%d.png
magick convert -density 150 "your-pdf.pdf" -background white -resize 1000x -flatten output.png
@KevinWang15
KevinWang15 / mustconverttype.go
Created June 19, 2024 03:49
MustConvertType converts an instance of type A to type B using JSON marshal and unmarshal.
// MustConvertType converts an instance of type A to type B using JSON marshal and unmarshal.
// Both types A and B should have the same structure and JSON tags.
// In case of error, it panics.
func MustConvertType[A any, B any](input A) B {
var output B
// Marshal the input type A to JSON
data, err := json.Marshal(input)
if err != nil {
panic(fmt.Errorf("failed to marshal input: %w", err))
@KevinWang15
KevinWang15 / main.go
Created June 13, 2024 05:17
TCP port forward through HTTP CONNECT PROXY
package main
import (
"bufio"
"fmt"
"io"
"io/ioutil"
"net"
"net/http"
"net/url"
@KevinWang15
KevinWang15 / glog.go
Created December 30, 2020 07:26
glog / klog with cobra
package main
import (
"flag"
"fmt"
"github.com/golang/glog"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
)
@KevinWang15
KevinWang15 / .zshrc
Created January 26, 2020 05:32
aliases
alias setp="export http_proxy=127.0.0.1:1087 && export https_proxy=127.0.0.1:1087"
alias unsetp="export http_proxy= && export https_proxy="
@KevinWang15
KevinWang15 / mysql.sh
Created April 23, 2018 16:42
backup mysql
#!/bin/bash
# crontab:
# 30 */8 * * * /root/backup/mysql.sh
databases=(db1 db2 db3)
basepath='/root/backup/mysql/'
<?php
/**
* 如果$_REQUEST中出现可能导致sql注入的字符,就返回400。
* 需要在程序一开始的时候就运行。
*
* 注意:本方法只对默认的html表单类型(application/x-www-form-urlencoded)有效
* 如果有文件上传类型的(enctype="multipart/form-data"),则不能执行本方法
*/
function guardAgainstBadCharactersInRequest()
@KevinWang15
KevinWang15 / config.js
Last active April 1, 2018 01:58
Upload JS/CSS to qiniu cdn for production in index.html, cache bust according to checksum
module.exports = {
qiniu_ak: '',
qiniu_sk: '',
qiniu_bucket: '',
qiniu_domain:'http://cdn.example.com'
};
@KevinWang15
KevinWang15 / after-build-cache-bust.js
Created March 4, 2018 16:37
General purpose cache buster ( after build ), append checksum to <script src="..."> and <link ref="...">, cache bust js & css in any build system
#!/usr/bin/env node
const INDEX_FILE_NAME = './www/index.html';
const fs = require('fs');
const path = require('path');
const crypto = require('crypto');
function checksum(str, algorithm, encoding) {
return crypto
.createHash(algorithm || 'md5')
.update(str, 'utf8')
@KevinWang15
KevinWang15 / JSCalendar.js
Last active March 4, 2018 08:21
JS Calendar - super simple & customizable, written in the form of angularjs, with calendar layout algorithm / "show today".
// adapted from https://stackoverflow.com/a/13786155/6247478
var cal_days_in_month = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
var month_names = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
var day_names = ['SUN', 'MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT'];
angular.module('demo')
.directive('calendar', function () {
return {
restrict: 'E',