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 / 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 / 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 / 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 / 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 / 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 / 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 / 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 / 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 / polyfill.bind.js
Last active April 26, 2024 04:52
Function bind(obj[, arg1[, arg2[, ...]]]) polyfill
if (typeof Function.prototype.bind === 'undefined') {
/**
* Function bind(obj[, arg1[, arg2[, ...]]]) polyfill
*
* @param obj
*
* @returns {Function}
*/
Function.prototype.bind = function (obj) {
var fn = this,
@mertenvg
mertenvg / autoscroll-into-view
Created July 27, 2014 14:02
Scroll to anchor with same name as current page. Uses jQuery.
/*
* Scroll to page section if it exists, but delay for a bit first.
*/
var page = location.href.replace(/^.+?\/?([^\/]+)$/i, '$1')
, delay = 500
, offset = -50
, $anchor;
if (page && ($anchor = $('a[name="'+page+'"]')).length) {
$('html,body').delay(delay).animate({scrollTop: $anchor.offset().top + offset}, 'slow');