Skip to content

Instantly share code, notes, and snippets.

View barlino's full-sized avatar

Barlino Yeh barlino

  • N Squared Ltd. Co.
  • Taipei, Taiwan
View GitHub Profile
@barlino
barlino / gist:2964376
Created June 21, 2012 07:21
divide the lyrics into sync and unsync lyrics
<?php
/**
目的:分流歌詞成同步歌詞與非同步歌詞。
step1 將文件內容轉換為UTF-8編碼
step2 針對文件內容每一行,判斷是否存在timecode,若有則為同步歌詞,反之為非同步
step3 若unsync長度少於十行,應從sync中過濾出非同步歌詞
step4 儲存
*/
require_once("encoding.php");
@barlino
barlino / gist:2964367
Created June 21, 2012 07:18
Get the string encoding via mb_detect_encoding()
/***
code from http://qiujiayu.iteye.com/blog/565929
*/
<?php
define ('UTF32_BIG_ENDIAN_BOM' , chr(0x00) . chr(0x00) . chr(0xFE) . chr(0xFF));
define ('UTF32_LITTLE_ENDIAN_BOM', chr(0xFF) . chr(0xFE) . chr(0x00) . chr(0x00));
define ('UTF16_BIG_ENDIAN_BOM' , chr(0xFE) . chr(0xFF));
define ('UTF16_LITTLE_ENDIAN_BOM', chr(0xFF) . chr(0xFE));
@barlino
barlino / gist:2964333
Created June 21, 2012 07:07
Get lorem via moretext.js
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" type="text/javascript"></script>
<script src="http://more.handlino.com/javascripts/moretext-1.1.js" type="text/javascript"></script>
<style>
#text1 {
-webkit-column-width: 200px;
-webkit-column-gap: 20px;
-webkit-column-rule: 3px solid #eee;
@barlino
barlino / gist:2964321
Created June 21, 2012 07:03
Spellcheck via Google API in Ruby
#!/usr/bin/env ruby
require 'rubygems'
require 'http_request'
require 'builder'
class Net::HTTP
alias_method :old_initialize, :initialize
def initialize(*args)
old_initialize(*args)
@ssl_context = OpenSSL::SSL::SSLContext.new
@barlino
barlino / gist:2964314
Created June 21, 2012 07:00
PHP – Generate/Create strong passwords, uuid, random string
//The code is from http://www.mcgarvie.net/2009/07/17/programming/php/php-generatecreate-strong-passwords-uuid-random-string made by Brian M McGarvie/
/**
Perfect for: PASSWORD GENERATION
Options: variable length
generateRandStr(8)
result: 4sRBfahW
**/
<?php
@barlino
barlino / gist:2952245
Created June 19, 2012 04:07
使用 trac-admin配置TRAC的訪問控制
trac-admin /path_to_repo/project
#list help
Trac[/path_to_repo/project]> ?
#list current permission
Trac[/path_to_repo/project]> permission list
User Action
--------------------------
anonymous BROWSER_VIEW
@barlino
barlino / gist:2952157
Created June 19, 2012 03:36
Using the magic gem to identify file mime type
#installation
gem install magic
#example
require "magic"
Magic.guess_file_mime("CKMetrics.pdf")
#=> "application/pdf; charset=binary"
@barlino
barlino / gist:2952146
Created June 19, 2012 03:33
use PHP5 for scanning directories recursively
<?
$dir = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator('/tmp'), true);
foreach ( $dir as $file ) {
echo str_repeat("--", $dir->getDepth()) . " $file\n";
}
?>
@barlino
barlino / gist:2952144
Created June 19, 2012 03:31
利用rsync支援續傳
alias rscp='rsync -v -P -e ssh'