Skip to content

Instantly share code, notes, and snippets.

View gonejack's full-sized avatar
💭
I may be slow to respond.

会有猫的 gonejack

💭
I may be slow to respond.
View GitHub Profile
@gonejack
gonejack / trim_for_chinese.php
Last active November 14, 2015 13:54
trim function for Chinese space characters
<?php
$s = preg_replace('^(([ \r\n\t])*( )*)*', '', $s);
$s = preg_replace('(([ \r\n\t])*( )*)*$', '', $s);
<?php
/**
* Convert bytes to human readable format
*
* @param integer bytes Size in bytes to convert
* @return string
*/
function bytesToSize($bytes, $precision = 2)
{
<?php
/**
* Created by PhpStorm.
* User: Youi
* Date: 2015-12-05
* Time: 02:47
*/
// buffer all upcoming output
ob_start();
@gonejack
gonejack / ObjectCompareFunc.js
Last active February 25, 2016 08:30
recursive compare
function recursiveCompare(a, b) {
if (!(a instanceof Object) && !(b instanceof Object)) {
return a === b;
}
else if (a instanceof Array && b instanceof Array) {
for (var i = 0, l = a.length; i < l; i++) {
if (recursiveCompare(a[i], b[i]) === false) {
return false;
}
@gonejack
gonejack / appendQuery.js
Created March 14, 2016 02:26
append query parameters to URL
function (url, name, value) {
if (url) {
var parser = document.createElement('a');
parser.url = url;
return url + [(parser.search ? '&' : '?'), name, '=', value].join('');
}
else {
return '';
}
@gonejack
gonejack / isInFrame.js
Created March 14, 2016 03:41
check if current page is iframe
'isInFrame': function () {
try {
return window.self !== window.top;
}
catch (e) {
return true;
}
}
@gonejack
gonejack / image-url-to-data-uri.js
Created August 7, 2017 15:42 — forked from oliyh/image-url-to-data-uri.js
Convert an image url to a data URI without canvas
// hard won knowledge from http://stackoverflow.com/questions/20035615/using-raw-image-data-from-ajax-request-for-data-uri
var xmlHTTP = xhr.XMLHttpRequest();
xmlHTTP.open('GET', url, true);
xmlHTTP.responseType = 'arraybuffer';
xmlHTTP.onload = function(e) {
var arr = new Uint8Array(this.response);
var raw = String.fromCharCode.apply(null,arr);
var b64 = base64.encode(raw);
var dataURL="data:image/png;base64," + b64;
};
@gonejack
gonejack / img-to-dataurl.js
Last active August 7, 2017 15:52
JS :: convert image to data url with javascript
console.clear();
var img = new Image();
img.src = 'img/img.png';
img.onload = function () {
var canvas = document.createElement('canvas'), context = canvas.getContext('2d');
canvas.width = img.width;
canvas.height = img.height;
context.drawImage(img, 0, 0, img.width, img.height);
console.log(canvas.toDataURL('image/png'));
public class MainClass {
public static void main(String[] args){
ClassLoader classLoader = MainClass.class.getClassLoader();
try {
Class aClass = classLoader.loadClass("com.jenkov.MyClass");
System.out.println("aClass.getName() = " + aClass.getName());
} catch (ClassNotFoundException e) {
Install Homebrew OS X package manager:
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Install ffmpeg with x265 support:
brew install ffmpeg --with-fdk-aac --with-sdl2 --with-freetype --with-libass --with-libvorbis --with-libvpx --with-opus --with-x265
Convert video to x265:
ffmpeg -i input -c:v libx265 -preset medium -crf 28 -c:a aac -b:a 128k output.mp4
Uninstall ffmpeg: