Skip to content

Instantly share code, notes, and snippets.

View MrPeak's full-sized avatar
🎯
Focusing

转二 MrPeak

🎯
Focusing
View GitHub Profile
const doc = context.document;
const action = doc.actionsController().actionForID("MSCollapseAllGroupsAction")
if (action.validate()) {
action.doPerformAction(nil);
}
// Open panel
var panel = NSOpenPanel.alloc().init();
[panel setCanChooseDirectories:true];
[panel setCanCreateDirectories:true];
// [panel setAllowedFileTypes:fileTypes];
//create variable to check if clicked
var clicked = [panel runModal];
@MrPeak
MrPeak / gist:472d54c068683439ce4d818a1490a065
Created May 25, 2017 12:40
Decode sketch json file's encoded textStyle
var bplist = require('bplist');
var plistBuf = new Buffer('YnBsaXN0MDDUAQIDBAUGFRZYJHZlcnNpb25YJG9iamVjdHNZJGFyY2hpdmVyVCR0b3ASAAGGoKMHCA9VJG51bGzTCQoLDA0OVU5TUkdCXE5TQ29sb3JTcGFjZVYkY2xhc3NGMSAxIDEAEAGAAtIQERITWiRjbGFzc25hbWVYJGNsYXNzZXNXTlNDb2xvcqISFFhOU09iamVjdF8QD05TS2V5ZWRBcmNoaXZlctEXGFRyb290gAEIERojLTI3O0FITltiaWttcn2GjpGarK+0AAAAAAAAAQEAAAAAAAAAGQAAAAAAAAAAAAAAAAAAALY=', 'base64')
bplist.parseBuffer(plistBuf, function(err, result) {
if (!err)
console.log(result); // [{key1: ['v', 'a', 'l', 'u', 'e'], key2: 'value2'}]
});
@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
@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 {

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

@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
@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 / 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 / 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;