Skip to content

Instantly share code, notes, and snippets.

@stephanbogner
stephanbogner / index.js
Created March 7, 2018 22:17
Create tree structure from paths array
var paths = [
["Account"],
["Account", "Payment Methods"],
["Account", "Payment Methods", "Credit Card"],
["Account", "Payment Methods", "Paypal"],
["Account", "Emails"],
["Account", "Emails", "Main Email"],
["Account", "Emails", "Backup Email"],
["Account", "Devices"],
["Account", "Devices", "Google Pixel"],
@dsager
dsager / devex_news_lab.md
Last active July 22, 2021 02:51
The Devex NewsLab: Using Google Docs as a CMS

The Devex NewsLab: Using Google Docs as a CMS

Note: This post was originally published on the Devex Tech Blog

This article describes our current content management solution and gives some insight on the parts of the implementation we think are interesting.

As you might know a big part of our website is dedicated to News content covering various aspects of international development. At Devex we usually publish around 10 articles per day which are sometimes planned and worked on several days or even weeks in advance. There are different people involved in the process including both internal and external writers, editors, researchers or marketing folks. Some of them contribute to the article's content while others just need to be aware what is going on to coordinate their own work like social media campaigns.

// Converts JSON string to JavaScript Object.
function jsonToObject(json) {
var str=[[NSString alloc] initWithString:json];
return [NSJSONSerialization JSONObjectWithData:str.dataUsingEncoding(NSUTF8StringEncoding) options:0 error:nil];
}
// Converts JavaScript Object to JSON string.
function objectToJson(obj,prettyPrint) {
var prettyPrint = prettyPrint || false;
@tylergaw
tylergaw / Generate Stylesheet.sketchplugin
Created June 8, 2014 22:03
Generate a CSS ruleset for every layer of the current page of a Sketch document
var allLayers = sketch.doc.currentPage().layers();
function createRuleSetStr (layer) {
var str = '';
var selector = '.' + layer.name().toLowerCase().replace(/ /gi, '-');
var attrs = layer.CSSAttributes();
str += selector + ' {';
for (var i = 0; i < attrs.count(); i += 1) {
@sergejmueller
sergejmueller / ttf2woff2.md
Last active March 9, 2024 13:37
WOFF 2.0 – Learn more about the next generation Web Font Format and convert TTF to WOFF2
@bomberstudios
bomberstudios / 2048.sketchplugin
Created April 23, 2014 13:49
Play 2048 inside Sketch.app, just because...
var URL = "http://gabrielecirulli.github.io/2048/"
var frame = NSMakeRect(0,0,340,480)
var webView = [[WebView alloc] initWithFrame:frame]
[[webView mainFrame] loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:URL]]]
var mask = NSTitledWindowMask + NSClosableWindowMask + NSMiniaturizableWindowMask + NSResizableWindowMask + NSUtilityWindowMask;
var window = [[NSPanel alloc] initWithContentRect:frame styleMask:mask backing:NSBackingStoreBuffered defer:true];
[[window contentView] addSubview:webView]
[window makeKeyAndOrderFront:nil]
@jeffehobbs
jeffehobbs / speaker.js
Last active December 26, 2015 12:59
Bookmarklet to scrub and speak current URL via SpeechSynthesisUtterance. (Please use your own Readability API token).
javascript:(function(e,a,g,h,f,c,b,d){if(!(f=e.jQuery)||g>f.fn.jquery||h(f)){c=a.createElement("script");c.type="text/javascript";c.src="http://ajax.googleapis.com/ajax/libs/jquery/"+g+"/jquery.min.js";c.onload=c.onreadystatechange=function(){if(!b&&(!(d=this.readyState)||d=="loaded"||d=="complete")){h((f=e.jQuery).noConflict(1),b=1);f(c).remove()}};a.documentElement.childNodes[0].appendChild(c)}})(window,document,"2.0.3",function($,L){
//speak current webpage
//jhobbs 2013
function stop(){
speechSynthesis.cancel();
}
@vjk2005
vjk2005 / download500px.js
Last active December 12, 2016 13:39
Download images from 500px
// Bookmarklet
javascript:(function() {
var a = document.createElement('a'), img_src = document.getElementsByClassName( 'the_photo' )[0].src;
a.href = img_src;
a.download = document.getElementsByClassName('name')[0].innerText + ' by ' + document.getElementsByClassName('author_name')[0].innerText + '.' + img_src.split('.').pop();
document.body.appendChild(a);
a.click();
})();
@MoritzStefaner
MoritzStefaner / .block
Last active January 20, 2020 10:46
Force-based label placement
license: apache-2.0
@marians
marians / german-porter-stemmer.js
Created April 26, 2011 14:06
German Porter Stemmer in JavaScript
/* by Joder Illi, Snowball mailing list */
function stemm(word) {
/*
Put u and y between vowels into upper case
*/
word = word.replace(/([aeiouyäöü])u([aeiouyäöü])/g, '$1U$2');
word = word.replace(/([aeiouyäöü])y([aeiouyäöü])/g, '$1Y$2');
/*
and then do the following mappings,