Skip to content

Instantly share code, notes, and snippets.

View mertenvg's full-sized avatar
🔍
Looking for a new opportunity #opentowork

Merten van Gerven mertenvg

🔍
Looking for a new opportunity #opentowork
View GitHub Profile
@mertenvg
mertenvg / trim_domain.php
Created July 31, 2013 07:34
Trim a domain to a specific number of levels
/**
* Trim a domain to a specific number of levels
*
* @param string $domain
* @param int $levels
*
* @return string
*/
function trim_domain($domain, $levels = 2)
{
@mertenvg
mertenvg / options-to-json.md
Created June 24, 2013 08:33
Converting option tags to json with regex

Converting option tags to json with regex

find    : <option [^>]*?value="([^"]+)"[^>]*>([^<]*)</option>
replace : "$1" : "$2",

Done!

@mertenvg
mertenvg / regex.md
Created June 6, 2013 09:33
Regex to convert copied 'describe {table};' results form navicat to entity properties

Regex MySQL Entity

Regex to convert copied 'describe {table};' results form navicat to entity properties

S: ^([a-z0-9_]+)[^;\n]+$
R: /**\n* @var string\n*/\npublic \$$1;
@mertenvg
mertenvg / ForeignScope.php
Created April 24, 2013 21:29
Get object or class vars of a specified class from an external scope ensuring that retrieved vars are public onlyue
<?php
namespace EntityMarshal;
class ForeignScope
{
/**
* @var ForeignScope Singleton instance.
*/
private static $instance;
@mertenvg
mertenvg / welcome.php
Created March 24, 2013 15:48
Basic key listener
function keyListener () {
var $next;
// if (event.keyCode === 37) { // left
//
// }
if (event.keyCode === 38) { // up
$next = $customerTypeOptionsItems.find('.active').prev();
if ($next.length === 0) {
@mertenvg
mertenvg / sample.js
Created March 12, 2013 10:18
Create node/module objects and be able to treat them as dom insertable nodes. Requires jQuery. Combined with jqPersist the object can be persisted with the node and linked up again later to maintain instance values etc.
(function ($) {
var myP = function (arg) {
this.init('<p />');
if (typeof $.fn.persist$ === 'function') {
this.persist$();
}
this.text(arg);
@mertenvg
mertenvg / jq.persist.js
Created March 12, 2013 10:08
Persist jQuery objects with its corresponding node so that additional values set on the object itself are maintained. Usage: // persist the jQuery object with the dom node (if one is persisted already then the new is ignored) $(selector).persist$(); // or override and existing persisted object $(selector).persist$(true); // then retrieve the per…
(function ($) {
var objCollection = [];
$.fn.persist$ = function (override) {
var current = this.data('oid');
if (typeof current === 'undefined') {
var next = objCollection.length;
@mertenvg
mertenvg / jquery.attention.js
Created February 20, 2013 12:52
A jQuery module/plugin to wobble/bounce elements in order to attract attention. Usage: $tooltip.seekAttention({ direction : 'right' }); $tooltip.stopSeekingAttention(); Default options: { effectClass : $.attention.effectClasses.Bounce, direction : 'right', elasticity : 0.4, interval : 5000, iterations : 0, force : 1, gravity : 0.3, friction : 0 }
(function ($) {
var intervalId;
var intervalCallback;
var frameInterval = 50;
var iterationCount = 0;
var collection = [];
$.attention = {
effectClasses : {
@mertenvg
mertenvg / iris.jquery.js
Last active December 11, 2015 15:18
Expand and collapse a container vertically on mouseover and mouseout. usage: $.iris($iconCtnr, 40, $iconCtnr.height(), '.selected');
$.iris = function (container, minHeight, maxHeight, keepInSightSelector, callback) {
var self = this;
var timeout = null;
var $container = $(container);
function handleKeepInSight () {
if (!keepInSightSelector) {
return;
}
@mertenvg
mertenvg / select_contents.function.js
Created January 23, 2013 11:18
Set the selection to the contents of the specified DOM element.
function select_contents(element) {
var selection = window.getSelection();
var range = document.createRange();
range.selectNodeContents(element);
selection.removeAllRanges();
selection.addRange(range);
}