Skip to content

Instantly share code, notes, and snippets.

View marsen's full-sized avatar
🕯️
Freedom

Marsen marsen

🕯️
Freedom
View GitHub Profile
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script>
$(function(){
$('#app-opener').bind('click',
function(){
var timer = setTimeout(function(){
alert('you not installed the x-myapp!!');
},1000);
@marsen
marsen / 自動產生亂數序號
Last active December 23, 2015 23:49
Auto Gen Random Keys by MSSQL
DECLARE @start INT = 1;
DECLARE @end INT = 50;
WITH #KEYS AS (
SELECT @start AS Number, REPLACE(LEFT(NEWID(), 18), '-', '') AS [KEY]
UNION ALL
SELECT Number + 1, REPLACE(LEFT(NEWID(), 18), '-', '') AS [KEY]
FROM #KEYS
WHERE Number < @end
)
SELECT * FROM #KEYS OPTION (MAXRECURSION 0)
@marsen
marsen / .On vs .Live in JQuery
Last active December 29, 2015 12:19
.On vs .Live in JQuery,Attach an event, now and in the future. Using jquery-1.8.3.min.js
<html>
<head>
<script src="http://code.jquery.com/jquery-1.8.3.min.js"></script>
<script>
$(function(){
$('#wrapper').on('click','#onlink',function(event){
alert('on link was clicked');
});
$("#livelink").live('click',function(){
alert('live link was clicked');
@marsen
marsen / random.js
Last active October 20, 2016 02:20
//隨機GUID
function RandomGUID(){
return 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8);
return v.toString(16);
});
}
//隨機整數
function RandomNum(Min,Max){
@marsen
marsen / templateReplace.js
Last active August 29, 2015 13:57
將template中所有的 {***} 變數 取代成 data[***]
////example
////http://goo.gl/FOMIgW
//template = '<li{is Selected}>{isChecked}<a href="/learn/{rootId}/topic/{courseId}">{indexStr} {courseName}</a></li>';
//var data = {
// isSelected: node.CourseId == Info.PageData.cId * 1 ? ' class="sel"' : "",
// isChecked: renderCheckedBox(node.CourseNodeType, node.Percentage, node.CourseId),
// indexStr: node.LevelIndex.join("-"),
// courseName: node.Name,
// rootId: Info.PageData.rId,
// courseId: node.CourseId
@marsen
marsen / parseURL.js
Created April 21, 2014 01:11
URL Parse
// This function creates a new anchor element and uses location
// properties (inherent) to get the desired URL data. Some String
// operations are used (to normalize results across browsers).
function parseURL(url) {
var a = document.createElement('a');
a.href = url;
return {
source: url,
protocol: a.protocol.replace(':',''),
@marsen
marsen / SQL Calendar
Created May 19, 2014 03:40
SQL Calendar
DECLARE @Date DATETIME
Set @Date = GetDate()
DECLARE @Start DATETIME,@End DATETIME
DECLARE @Index INT
SET @Start = DATEADD(MONTH,DATEDIFF(MONTH,0,@Date),0)
SET @End = DATEADD(MONTH,1,@Start)
SET @Index = DATEDIFF(DAY,-1,@Start)%7 - 1;
SET @Start = DATEADD(mm,DATEDIFF(mm,0,@Date),0)
SET @End = DATEADD(mm,1,@Start) - 1
SET @Index= DATEDIFF(day,0,@Start)%7
@marsen
marsen / NamespacePattern.js
Last active August 29, 2015 14:01
namespace pattern (命名空間模式)
//namespace pattern
var MYAPP = MYAPP || {};
MYAPP.namespace = function(ns_string){
var parts = ns_string.split('.'),
parent = MYAPP,
i;
if(parts[0]==="MYAPP"){
parts = parts.slice(1);
}
@marsen
marsen / Sql_Slipt.sql
Created May 26, 2014 00:43
SQL Slipt
CREATE FUNCTION [dbo].[UF_SliptToTable]
(
@psCSString VARCHAR(8000)
)
RETURNS @otTemp TABLE(sID VARCHAR(100))
AS
BEGIN
DECLARE @sTemp VARCHAR(100)
WHILE LEN(@psCSString) > 0
@marsen
marsen / stopEventBubble.js
Last active August 29, 2015 14:03
Stop Event Bubble
function stopEventBubble(e) {
if (e && e.stopPropagation) {
e.stopPropagation();
}
else {//why always IE
window.event.cancelBubble = true;
}
}