Skip to content

Instantly share code, notes, and snippets.

View kayhadrin's full-sized avatar

David kayhadrin

  • AU-US in betweener
View GitHub Profile
@kayhadrin
kayhadrin / index.html
Created July 21, 2013 04:34
A CodePen by David. Custom Rivets binder for jQuery plugins - Example of how to write a custom rivet binder for jQuery plugins that report changes with custom events.
<!-- JS Includes -->
<script src="//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.4.4/underscore-min.js" type="text/javascript"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/backbone.js/1.0.0/backbone.js" type="text/javascript"></script>
<script src="https://rawgithub.com/mikeric/rivets/master/dist/rivets.js" type="text/javascript"></script>
<script src="https://rawgithub.com/azproduction/rivets-backbone-adapter/master/rivets-backbone.js" type="text/javascript"></script>
<p style="color: red;">
Open your dev tools and watch the console log for output. You should notice that when setting the value manually using the Backbone set(), the "routine" is fired off twice.
</p>
@kayhadrin
kayhadrin / index.js
Created January 4, 2014 00:33
requirebin sketch
var MemDB = require('memdb');
var db = MemDB();
console.log('memdb db = ', db);
@kayhadrin
kayhadrin / Dynamic-column-width-with-css-calc().markdown
Last active August 29, 2015 14:08
Dynamic column width with css calc()

Dynamic column width with css calc()

The general formula of the column width for a known separator width is columnWidth = ( fullWidth + separatorWidth * (1 - columnNb) ) / columnNb

A Pen by David on CodePen.

@kayhadrin
kayhadrin / index.html
Created November 12, 2014 23:22
A Pen by David.
<div>
<span>
<a class="menu-item">Home</a>
</span>
<span>
<a class="menu-item">Contact</a>
</span>
</div>
@kayhadrin
kayhadrin / .bashrc
Last active October 9, 2015 00:11
bash config
# Git aliases
alias g="git"
alias gits="git status"
alias gitc="git commit"
alias gitb="git branch"
alias gs='git status'
alias gc='git commit'
alias gb='git branch'
alias gbr='git branch -r'
alias gf='git fetch && git fetch --tags'
@kayhadrin
kayhadrin / jquery-trackScroll.js
Created December 1, 2015 08:52
jQuery plugin to raise custom scroll_vertical and scroll_horizontal events
/**
* Simple plugin to track scroll events and trigger a custom jQuery event (scroll_vertical or scroll_horizontal)
* when the corresponding type of scroll has happened.
* Event handlers can receive the original scroll event and the scroll delta as second values.
* e.g. function(jqEvent, scrollEvent, delta)
*
* To stop this, unbind the 'scroll.trackScroll.vertical' or 'scroll.trackScroll.horizontal' event
* @param {string} direction Scroll direction to track
* @return {jQuery}
*/
@kayhadrin
kayhadrin / triggerMouseEvent.js
Last active February 6, 2023 16:49
Trigger mouse event programmatically. Useful to simulate mouse wheel events.
/**
* Simulate a mouse event to a given DOM element
* @param {string, WebElement} elem
* @param {string} evtName Event name
* @param {object} eventInitProps Properties to set on the mouse event
*/
function triggerMouseEvent(elem, evtName, eventInitProps) {
return browser.executeScript(function(_elem, _evtName, _eventInitProps) {
var $ = window.jQuery;
elem = $(_elem);
@kayhadrin
kayhadrin / pslist.bat
Last active April 5, 2016 20:24
Show details process list in command line
@echo off
rem Shows the list of current running processes
rem Run "WMIC path win32_process" to get further process details
WMIC path win32_process get Caption,Processid,Commandline
@kayhadrin
kayhadrin / js-timeout-polyfill.js
Last active February 28, 2023 17:52
Nashorn setTimeout polyfill
/**
* js-timeout-polyfill
* @see https://blogs.oracle.com/nashorn/entry/setinterval_and_settimeout_javascript_functions
*/
(function (global) {
'use strict';
if (global.setTimeout ||
global.clearTimeout ||
global.setInterval ||
@kayhadrin
kayhadrin / q-allSettled.js
Created July 29, 2016 20:09
Useful additions to $q
/**
* $q.allSettled returns a promise that is fulfilled with an array of promise state snapshots,
* but only after all the original promises have settled, i.e. become either fulfilled or rejected.
*
* This method is often used in order to execute a number of operations concurrently and be
* notified when they all finish, regardless of success or failure.
*
* @param promises array or object of promises
* @returns {Promise} when resolved will contain an an array or object of resolved or rejected promises.
* A resolved promise have the form { status: "fulfilled", value: value }. A rejected promise will have