Skip to content

Instantly share code, notes, and snippets.

View ktmud's full-sized avatar
🥌
Peace and Love~

Jesse Yang ktmud

🥌
Peace and Love~
View GitHub Profile
@ktmud
ktmud / anim.coffee
Last active August 29, 2015 13:56
Enable `animate.css` with jQuery animation queue
ANIMATION_END = "webkitAnimationEnd mozAnimationEnd
MSAnimationEnd oanimationend
animationend"
$.fn.anim = (cls, options, nextDelay) ->
@removeClass("animated #{@data('_last_anim')}")
@data '_last_anim', cls
if 'number' is typeof options
options = { duration: "#{options/1000}s" }
if options?
@ktmud
ktmud / trunc.js
Created April 3, 2014 10:18
trunc text based on locale
String.prototype.blength = function() {
return this.replace(/\n\r/g, '\n').replace(/[^\x00-\xff]/g, 'xx').length;
};
function btrunc(text, limit) {
limit = Number(limit) || 10
if (text.blength() < limit * 2) {
return text
}
var ret = '', count = 0, i = 0, max = limit * 2 - 2
@ktmud
ktmud / search.coffee
Last active August 29, 2015 14:01
amap api autocomplete with Typeahead
TT_TEMPLATES =
suggestion: (d) ->
"<p>#{d.name} <small class=\"district\">#{d.district}</small></p>"
map = new AMap.Map elem, level: 4
map.plugin ['AMap.Autocomplete'], =>
bb = new Bloodhound
datumTokenizer: (d) -> [d.name, d.district]
@ktmud
ktmud / gist:1825369
Created February 14, 2012 09:41
responsive test jade template
!!!
html
head
title Responsive Test
<style>body { margin: 20px; font-family: sans-serif; overflow-x: scroll; }.wrapper { width: 6000px; }.frame { float: left; }h2 { margin: 0 0 5px 0; }iframe { margin: 0 20px 20px 0; border: 1px solid #666; }</style>
body
- sizes = [ [240, 320, 'mobile'], [320, 480, 'mobile'], [480, 640, 'small tablet'], [768, 1024, 'tablet - portrait'], [1024, 768, 'tablet - landscape'], [1200, 800, 'desktop'], ];
.wrapper
each item in sizes
.frame
@ktmud
ktmud / seajs-bigpipe.js
Created February 14, 2012 10:56
BigPipe with SeaJS
// this script should be inline
(function(win, doc, seajs) {
var $ = function(id) {
if (typeof id == 'string') return document.getElementById(id);
return id;
};
$.uuid = 0;
/**
* @param {array} funs 需要执行的函数,一个文本数组.
@ktmud
ktmud / app.danamicHelpers.js
Created February 18, 2012 17:20
inline compressed static files for express
var conf = central.conf;
var reg_val = /#{([^}]+)}/g;
module.exports = function(app) {
app.helpers({
DEBUG: conf.debug
});
app.dynamicHelpers({
// inline static
istatic: function(req, res) {
@ktmud
ktmud / value-placeholder.js
Created July 31, 2012 08:46
input placeholder using elem.value
(function() {
var canNative = (function() {
var elem = document.createElement('input');
return 'placeholder' in elem;
})();
$.fn.placeholder = function(text, cls, noNative) {
var self = this;
text = text || '';
cls = cls || 'blur';
if (!noNative && canNative) {
@ktmud
ktmud / dabblet.css
Created August 2, 2012 07:38
The first commented line is your dabblet’s title
/**
* The first commented line is your dabblet’s title
*/
background: #f06;
background: linear-gradient(45deg, #f06, yellow);
min-height: 100%;
@ktmud
ktmud / boot.sh
Created November 12, 2012 11:59
Git部署多个NodeJS应用
#... 加入你的启动脚本中
su www -c "/srv/nodejs/nogo.sh weixin halt reboot"
su www -c "/srv/nodejs/nogo.sh loudlaw halt reboot"