Skip to content

Instantly share code, notes, and snippets.

View seutje's full-sized avatar

Steve De Jonghe seutje

View GitHub Profile
@seutje
seutje / Paranoia-escape-js.php
Created January 15, 2016 14:34
PHP helper function to escape javascript strings like a true paranoid mofo
<?php
/**
* Extremely paranoid escaping function for use with inline JS strings.
*
* Escapes every single character to a \x# format.
*
* @param string
*
* @return string
@seutje
seutje / drupalspy.bookmarklet.js
Last active October 9, 2015 09:48
Bookmarklet for easily inspecting drupal sites
javascript:(function(){var t=document.querySelector('meta[name="generator"], meta[name="Generator"]');alert(t?t.getAttribute("content"):"No generator meta tag found.")})();
@seutje
seutje / d3.simplecluster.js
Last active October 8, 2015 13:19
Example map pin clustering based on PX distance.
var foo = {
init: function(i, el) {
this.wrapper = el;
this.baseMarkerRadius = 2.5; // Base size of a cluster.
this.markerRadiusExpand = 1.5; // Added radius based on cluster size (e.g. 4 in a cluster, radius = 2.5 + 4 * 1.5)
this.clusterDistance = 10; // Distance in pixels for clustering.
this.offset = 268435456; // Half the circumference of the earth at zoom level 21 and in pixels.
this.radius = this.offset / Math.PI; // Used for clustering logic.
var that = this; // Scope us a reference.
var width = 940,
@seutje
seutje / jquery.wrapeach.js
Last active September 2, 2015 07:52
Little jQuery plugin to wrap every X items.
/**
* Wraps every num elements with el.
*
* Usage: $('.foo').wrapEach('<div></div>', 5);
* Wraps every 5 .foo's with a <div>, defaults to 2.
*/
$.fn.wrapEach = function(el, num) {
num = num || 2;
for (var i = 0; i < this.length; i += num) {
this.slice(i, i + num).wrapAll(el);
@seutje
seutje / somemodule.module.php
Last active August 29, 2015 14:25
Custom DS fields example (remove .php from filename, only for github code highlighter)
<?php
function somemodule_ds_fields_info($entity_type) {
$fields = array();
$fields['node']['some_field'] = array(
// Arbitrary UI label.
'title' => t('Some field'),
// DS constant for field type function.
'field_type' => DS_FIELD_TYPE_FUNCTION,
// Name of the actual function.
@seutje
seutje / listFonts.jsx
Last active September 17, 2015 13:20
Helper script to list all different fonts used in a specific Photoshop document. Do note that the PSD needs to be saved somewhere, a .csv file will be generated in the same folder listing all the font variants.
var nicer_obj = function (obj) {
var new_obj = {}
for (key in obj) {
if (obj.hasOwnProperty(key)) {
try { new_obj[key] = obj[key]; } catch (err) {}
}
}
return new_obj;
}
@seutje
seutje / findDeepest.js
Created September 26, 2014 13:50
Find deepest element
function findDeepest (elem) {
var result = {maxDepth: 0, deepestElem: null}
descend(elem, 0, result);
if (result.maxDepth > 0)
console.log(result);
}
function descend(elem, depth, result) {
switch (elem.nodeType) {
@seutje
seutje / autowoot.js
Last active August 29, 2015 14:06
autowoot for plug.dj
//Open your browser's console tab (F12 and click the console tab) and paste it there. Refresh the page to unload the script.
;(function(){
API.on(API.ADVANCE,callback).trigger(API.ADVANCE);
function callback(){
$('#woot').click();
}
})();
// Bookmark: javascript:(function(c){c=function(){$('#woot').click();};API.on(API.ADVANCE,c).trigger(API.ADVANCE);}());
@seutje
seutje / techwobbles.js
Last active August 29, 2015 14:04
Techwobbles
/*!
*
* stagas - mind swift (seutje techwobbles mix)
*
*/
var bpm = 130;
var tuning = 440;
var transpose = 11;
var hardcodedTimer = 7.4;
@seutje
seutje / triphops.js
Last active August 29, 2015 14:04
triphops for wavepot
/*!
*
* stagas - mind swift (seutje triphop mix)
*
*/
var bpm = 130;
var tuning = 440;
var transpose = 11;