Skip to content

Instantly share code, notes, and snippets.

View hjue's full-sized avatar

hjue hjue

  • Beijing, China
View GitHub Profile
@hjue
hjue / gist:3910561
Created October 18, 2012 09:00
getNumPagesInPDF
<?php
echo getNumPagesInPDF('iOS-zhangchao.pdf');
function getNumPagesInPDF($PDFPath)
{
$stream = @fopen($PDFPath, "r");
$PDFContent = @fread ($stream, filesize($PDFPath));
if(!$stream || !$PDFContent)
return false;
$firstValue = 0;
$secondValue = 0;
@hjue
hjue / nginx.conf
Created April 22, 2013 05:30 — forked from hydra35/nginx.conf
# 1. Make sure you have nginx sub module compiled in
# nginx -V 2>&1 | grep --color=always '\-\-with\-http_sub_module'
# 2. add two directives below at HTTP level
# nginx.conf
http {
# ......
sub_filter '</head>' '<style type="text/css">html{ filter:progid:DXImageTransform.Microsoft.BasicImage(grayscale=1); -webkit-filter: grayscale(100%); filter: url("data:image/svg+xml;utf8,<svg xmlns=\'http://www.w3.org/2000/svg\'><filter id=\'grayscale\'><feColorMatrix type=\'matrix\' values=\'0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0 0 0 1 0\'/></filter></svg>#grayscale"); /* Firefox 10+, Firefox on Android */
<html>
<head>
<title>WebSocket Demo</title>
</head>
<style type="text/css">
textarea{width:400px;height:150px;display:block;overflow-y:scroll;}
#output{width:600px;height:400px;background:whiteSmoke;padding:1em .5em;color:#000;border:none;}
button{padding:.2em 1em;}
</style>
<link href="layout.css" rel="stylesheet" type="text/css" />
@hjue
hjue / my_tmux
Last active December 16, 2015 17:41
my tmux shell
#!/bin/sh
#
cmd=$(which tmux)
session=hjue
if [ -z $cmd ]; then
echo "You need to install tmux."
exit 1
fi
@hjue
hjue / ExampleClass.m
Created May 11, 2013 03:07 — forked from lukeredpath/ExampleClass.m
GCDSingleton
@implementation MySharedThing
+ (id)sharedInstance
{
DEFINE_SHARED_INSTANCE_USING_BLOCK(^{
return [[self alloc] init];
});
}
@end
@hjue
hjue / Minify.pm
Last active April 11, 2016 17:50
EmbeddedPerlMinifyJS
package Minify;
use nginx;
use JavaScript::Minifier qw(minify);
sub handler {
my $r=shift;
my $cache_dir="/tmp";
my $cache_file=$r->uri;
$cache_file=~s!/!_!g;
$cache_file=$r->header_in("Host").$cache_file;
#import <CoreLocation/CoreLocation.h>
#import <ImageIO/ImageIO.h>
@interface CLLocation (EXIFGPS)
- (NSDictionary*) EXIFMetadataWithHeading:(CLHeading*)heading;
@end
@interface NSDate (EXIFGPS)
@hjue
hjue / gist:7557197
Created November 20, 2013 03:27
Twig CI Library
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
/*
* Created on 2013-10-25 by hjue
* Twig CI Library
*
*/
require_once APPPATH . 'third_party/Twig/Autoloader.php';
class Twig {
@hjue
hjue / gist:7686962
Last active December 29, 2015 14:49
Log Library for Codeigniter
<?php defined('BASEPATH') OR exit('No direct script access allowed');
/**
* CodeIgniter Log Library
*
* @category Applications
* @package CodeIgniter
* @subpackage Libraries
* @author hjue
* @license BSD License
@hjue
hjue / UAMacros.h
Created December 8, 2013 09:04
UAMacros.h
#define UA_isIPad (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
#define UA_isIPhone (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
#define UA_isRetinaDevice ([[UIScreen mainScreen] respondsToSelector:@selector(scale)] && [[UIScreen mainScreen] scale] >= 2)
#define UA_isMultiTaskingSupported ([[UIDevice currentDevice] respondsToSelector:@selector(isMultitaskingSupported)] && [[UIDevice currentDevice] isMultitaskingSupported])
#define UA_runOnMainThread if (![NSThread isMainThread]) { dispatch_sync(dispatch_get_main_queue(), ^{ [self performSelector:_cmd]; }); return; };