Skip to content

Instantly share code, notes, and snippets.

View MrPeak's full-sized avatar
🎯
Focusing

转二 MrPeak

🎯
Focusing
View GitHub Profile
@MrPeak
MrPeak / CommonJs in Front&Back End
Created December 12, 2013 06:11
A compatible solution for server & browser javascript.
;(function(libName, libBody) {
var hasDefine = typeof define === 'function';
hasExports = typeof module !== "undefined" && module.exports;
if(hasDefine) {
if(define.AMD) {
// AMD environment
define(libBody);
@MrPeak
MrPeak / app.js
Created December 27, 2013 06:05
A fixed navigation demo which depended on jQuery. desc: http://jsfiddle.net/mrpeak/BTdY9/1/
$(function () {
$('#navigation a').stop().animate({
'marginLeft': '-85px'
}, 1000);
$('#navigation > li').hover(
function () {
$('a', $(this)).stop().animate({
'marginLeft': '-2px'
@MrPeak
MrPeak / observe.js
Created December 27, 2013 06:11
Observer pattern.( Based on JavaScript object )
// 观察者模式
var observer = {
addSubscriber: function (callback) {
this.subscribers[this.subscribers.length] = callback;
},
removeSubscriber: function (callback) {
var len = this.subscribers.length,
i;
@MrPeak
MrPeak / sleep.js
Created December 27, 2013 18:43
Simulate 'sleep( )' function in PHP with JavaScript.
// define
var sleep = function(seconds) {
var start = (new Date)['getTime'](),
i = 1e8;
while (i--) {
if ((new Date)['getTime']() - start >= seconds * 1e3) { // must be gte!
return false;
}
}
@MrPeak
MrPeak / boilerplate.js
Created January 2, 2014 06:29
jQuery plugin boilerplate
;(function($) {
// multiple plugins can go here
(function(pluginName) {
var defaults = {
color: 'black',
testFor: function(div) {
return true;
}
};
$.fn[pluginName] = function(options) {
@MrPeak
MrPeak / jquery.jsortable.js
Created January 10, 2014 12:55
Plugin to make sortable table for jQuery
/**
* sortable table plugin for jQuery
* @autor - gaofeng <gfeng.peak@gmail.com>
* @desc - make table sortable
* @version 0.1
*/
(function() {
/**
* Determine whether the string contains Chinese

// // oo0oo // o8888888o // 88" . "88 // (| -_- |) // 0\ = /0 // _/`---'_ // .' \| |// '. // / \||| : |||//
// / _||||| -:- |||||- \

@MrPeak
MrPeak / SassMeister-input.scss
Created November 12, 2015 03:05
Generated by SassMeister.com.
// ----
// libsass (v3.2.5)
// ----
@mixin rgba($property, $background, $opacity, $mix: white) {
#{$property}: mix($background, $mix, $opacity * 100%);
#{$property}: rgba($background, $opacity);
@if 1 == 1 {
@MrPeak
MrPeak / browser JS unzip file
Last active June 13, 2017 12:30
A small node script that reads a sketch file, changes a layer name on the page, and saves back to that file
const fs = require('fs');
// lib to read and write to the zip
const JSZip = require('jszip');
fs.readFile('Untitled3.sketch', function(err, data) {
if(err) throw err;
JSZip.loadAsync(data).then(function(zip) {
// zip contains a json file that describes all the directory & files in the zip file