Skip to content

Instantly share code, notes, and snippets.

View 0xffan's full-sized avatar
🔨
building...

X.F. 0xffan

🔨
building...
  • Chengdu, China
View GitHub Profile
#!/bin/bash
#script extraido de: http://paulocassiano.wordpress.com/2008/08/29/deixando-o-gedit-com-a-cara-do-textmate/
#tip for better "resolution" here: http://blog.siverti.com.br/2008/05/22/fonte-monaco-no-ubuntugedit/
cd /usr/share/fonts/truetype/
#TODO: put validation if folder already exists
sudo mkdir ttf-monaco
@0xffan
0xffan / .vimrc
Last active December 30, 2015 16:19
My Vim config
"======================================
" Author: WarrenFan
" Last Modified: 2013-12-08
" Sections:
" > General
" > View
" > Utility
" > Plugins
"======================================
@0xffan
0xffan / ascii_art_buddha
Created August 26, 2014 13:53
ascii art - Buddha
_
_ooOoo_
o8888888o
88" . "88
(| -_- |)
O\ = /O
____/`---'\____
.' \\| |// `.
/ \\||| : |||// \
/ _||||| -:- |||||_ \
popupWins = new Array();
function windowOpener(url, name, args) {
/*******************************
the popupWins array stores an object reference for
each separate window that is called, based upon
the name attribute that is supplied as an argument
*******************************/
if ( typeof( popupWins[name] ) != "object" ){
popupWins[name] = window.open(url,name,args);
@0xffan
0xffan / basic.html
Last active August 29, 2015 14:13 — forked from tobiastom/basic.html
<!DOCTYPE html>
<script type="text/javascript">
if ( window.name == 'popup' ) {
document.body.className += ' in-popup'
}
function selectItemInPopup(item) {
window.opener.popupDidSelectItem(window.item);
window.close();
}
@0xffan
0xffan / jsPopupWindow.js
Created January 11, 2015 12:59
Communication
var popupWindow = window.open("popupWindow.html", "WindowName", "width=100, height=30, menubar=no, resizable=no, scrollbars=no");
whenPopupClosed(popupWindow, callback);
var whenPopupClosed = function (popupWindow, callback) {
var pollTimer = window.setInterval(function() {
if (popupWindow.closed !== false) { // !== is required for compatibility with Opera
window.clearInterval(pollTimer);
callback();
}
}, 200);
@0xffan
0xffan / Apache Commons FileUpload
Created March 30, 2015 06:26
File uploading with apache-commons-fileupload
import java.io.InputStream;
import java.util.List;
import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.FilenameUtils;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
List<FileItem> items = new ServletFileUpload(new DiskFileItemFactory()).parseRequest(request);
for (FileItem item : items) {
@0xffan
0xffan / ParseDateFromADTimestamp
Last active January 27, 2023 16:12
Parse date from Windows epoch timestamp.
// The difference between the Windows epoch (1601-01-01 00:00:00) and the Unix epoch (1970-01-01 00:00:00) in milliseconds: 11644473600000L.
private final static long WINDOWS_UNIX_EPOCH_DIFF_MILLISECONDS = 11644473600000L;
public static Date parseDateFromADTimestamp(String strADTimestamp) {
long adTimestamp = Long.parseLong(strADTimestamp);
long millisecondsTime = (adTimestamp / 10000) - WINDOWS_UNIX_EPOCH_DIFF_MILLISECONDS;
Date date = new Date(millisecondsTime);
return date;
}
@0xffan
0xffan / humanReadableByteCount
Created March 30, 2015 06:41
Human readable byte count
public static String humanReadableByteCount(long bytes, boolean si) {
int unit = si ? 1000 : 1024;
if (bytes < unit) return bytes + " B";
int exp = (int) (Math.log(bytes) / Math.log(unit));
String pre = (si ? "kMGTPE" : "KMGTPE").charAt(exp-1) + (si ? "" : "i");
return String.format("%.1f %sB", bytes / Math.pow(unit, exp), pre);
}
@0xffan
0xffan / Dorm-network.scpt
Last active September 2, 2015 15:21 — forked from Jeff2Ma/Dorm-network.scpt
Automatic proxy configuration set pac file with applescript & shell script http://devework.com/automatic-proxy-configuration-pac-applescript.html
tell application "System Events"
tell network preferences
do shell script "scselect 'Dorm'"
do shell script "sudo networksetup -setairportpower AirPort on" user name "用户名" password "密码" with administrator privileges
do shell script "open /Applications/Shad**socksX.app" user name “用户名" password "密码" with administrator privileges
end tell
end tell