Skip to content

Instantly share code, notes, and snippets.

@RhinoLu
RhinoLu / placeholder.scss
Last active March 15, 2016 09:09
placeholder style
input {
position: absolute;
left: 10px;
top: 35px;
width: 280px;
height: 30px;
padding: 0;
margin: 0;
border: 0;
background-color: transparent;
@RhinoLu
RhinoLu / enter.js
Created March 15, 2016 09:08
Trigger a button click with JavaScript on the Enter key in a text box
$(".someone>input").keyup(function(event){
if(event.keyCode == 13){
$("#someone").click();
}
});
@RhinoLu
RhinoLu / getAndroidVersion.js
Created January 15, 2016 07:46
js get android version
// http://stackoverflow.com/questions/7184573/pick-up-the-android-version-in-the-browser-by-javascript
function getAndroidVersion(ua) {
ua = (ua || navigator.userAgent).toLowerCase();
var match = ua.match(/android\s([0-9\.]*)/);
return match ? match[1] : false;
};
getAndroidVersion(); //"4.2.1"
parseInt(getAndroidVersion(), 10); //4
parseFloat(getAndroidVersion()); //4.2
@RhinoLu
RhinoLu / ios_webview.txt
Created December 10, 2015 12:08
detect iOS webview
Safari and UIWebView give mostly the same User Agent, but UIWebView is missing Version/* and Safari/*.
@RhinoLu
RhinoLu / addZero.js
Created December 1, 2015 11:26
補零
function addZero(str: string, length: number): string {
return new Array(length - str.length + 1).join("0") + str;
}
@RhinoLu
RhinoLu / gist:ab3b0d88c79d6a479a46
Created November 1, 2015 13:43 — forked from tony1223/gist:ac9aec20561112e6e43c
台灣身分證檢查
function identify(check){
var type = {a:10, b:11, c:12, d:13, e:14, f:15, g:16, h:17, j:18, k:19, l:20, m:21, n:22, p:23, q:24, r:25, s:26, t:27, u:28, v:29, w:32, x:30, y:31, z:33, i:34, o:35 };
var val = type[check[0].toLowerCase()] + check.substring(1);
var ranks = [1,9,8,7,6,5,4,3,2,1];
var checknum = 0;
for(var i = 0 ; i < ranks.length;++i){
checknum += parseInt(val[i],10) * ranks[i];
@RhinoLu
RhinoLu / validation.ts
Last active March 9, 2016 08:55
form validation 表單驗證
checkForm(): boolean {
var msg: string = "";
if ($("#form_name").val().length < 1) {
msg += "請輸入中文姓名\n";
}else{
var chineseCount: number = $("#form_name").val().split(/[\u4e00-\u9fa5]/).length - 1;
trace("chineseCount : " + chineseCount);
trace("姓名.length : " + $("#form_name").val().length);
if($("#form_name").val().length != chineseCount){
@RhinoLu
RhinoLu / gist:f5c97fcc3bd1abf796dd
Created June 30, 2015 03:30
safari 捲動 Scrolling on iOS Overflow Elements
// https://css-tricks.com/snippets/css/momentum-scrolling-on-ios-overflow-elements/
.module {
width: 300px;
height: 200px;
overflow-y: scroll; /* has to be scroll, not auto */
-webkit-overflow-scrolling: touch;
}
@RhinoLu
RhinoLu / gist:9630d28f240a847b6aba
Last active October 14, 2015 11:20
判斷字串中有幾個中文字 check how many chinese words in a string
var str = "test 測試";
var chineseCount = str.split(/[\u4e00-\u9fa5]/).length - 1;
console.log(chineseCount);
@RhinoLu
RhinoLu / BitmapDataUtils.as
Created January 27, 2015 15:57
(AS3)利用 BitmapData.draw 對位圖進行翻轉縮放操作
package org.easily.utils
{
import flash.display.BitmapData;
import flash.geom.Matrix;
public class BitmapDataUtils
{
//水平翻轉一個位圖
public static function flipHorizontal(bmpData:BitmapData, transparent:Boolean = true, fillColor:uint = 0):BitmapData
{