Skip to content

Instantly share code, notes, and snippets.

View victornpb's full-sized avatar
⌨️

Victor victornpb

⌨️
View GitHub Profile
@victornpb
victornpb / dabblet.css
Created January 24, 2013 18:02
A "deeper" indented text effect with the :before and :after pseudo-elements.
/**
* A "deeper" indented text effect with the :before and :after pseudo-elements.
*/
html, body {
height: 100%;
}
body {
margin: 0;
@victornpb
victornpb / fpsMeter
Created December 1, 2013 03:49
fpsMeter for javascript animations
/**
* FPS Meter
* @author Victor N - www.vitim.us
*
* @param {function} callback Function that will display the fps rate
* @param {number} refreshRate Defines the frequency the fps will be updated in ms
* @returns {function}
*/
function fpsMeter(callback, refreshRate){
@victornpb
victornpb / HideAddressBar.js
Created December 1, 2013 17:04
Hide the address bar on mobile devices.
/** Hide the address bar - vitim.us */
function hideAddressBar(){
setTimeout(function(){
if(scrollY) return;
scrollTo(scrollX, 1);
setTimeout(function()
if(scrollY==1)
scrollTo(scrollX, 0);
}, 1);
}, 1);
@victornpb
victornpb / occurrences.js
Last active June 7, 2023 14:37
Function count the occurrences of substring in a string
/** Function that count occurrences of a substring in a string;
* @param {String} string The string
* @param {String} subString The sub string to search for
* @param {Boolean} [allowOverlapping] Optional. (Default:false)
*
* @author Vitim.us https://gist.github.com/victornpb/7736865/edit
* @see Unit Test https://jsfiddle.net/Victornpb/5axuh96u/
* @see http://stackoverflow.com/questions/4009756/how-to-count-string-occurrence-in-string/7924240#7924240
*/
function occurrences(string, subString, allowOverlapping) {
@victornpb
victornpb / format.js
Created December 1, 2013 22:26
format string "Hello {0}, {1}"
/** format string
* format("Hello {0}! {1}-{2}.", "World", "foo", "bar") --> "Hello World! foo-bar."
*/
function format(string, etc) {
var args = arguments;
return string.replace(/{(\d+)}/g, function(match, number) {
return typeof args[+number+1]!="undefined" ? args[+number+1] : match;
});
}
@victornpb
victornpb / tag.js
Created April 23, 2014 03:32
Function to template DOM tags
//create element
function tag(tag, attributes, childs){
function isArray(o) {
return Object.prototype.toString.call(o) === "[object Array]";
}
function isElement(o) {
return !!(o && o.nodeType == 1);
}
function isTextNode(o) {
@victornpb
victornpb / addEvent.js
Last active August 29, 2015 14:00
function addEvent(element, trigger, action)
/**
* Add a event to a element;
* @param {Object} element Element or ID;
* @param {String} trigger Trigger to fire action eg:load,click,mouseover,etc;
* @param {Function} action A pointer to a function to be called on trigger;
*/
function addEvent(element, trigger, action){
if(typeof element==="string"){element=document.getElementById(element);}
if(element.addEventListener){
element.addEventListener(trigger,action,false);
@victornpb
victornpb / AsyncLoop.js
Last active August 29, 2015 14:00
Constructor that create a Loop object to run blocking loops, but allow it to be interrupted when requested to give a change to make DOM updates.
/** Constructor that create a Loop object to run blocking loops, but allow
* it to be interrupted when requested to give a change to make DOM updates
* @author Victor B - www.vitim.us
*/
function AsyncLoop(){
this.loop; //called on every loop
this.onUpdate; //called when the loop is interrupted
this.onComplete; //called when the loop is finished
this.requestInterruptToUpdateDOM = false;
@victornpb
victornpb / fpsMeter.js
Created April 23, 2014 04:22
FPS Meter - Returns a function that is used to compute the framerate without the overhead of updating the DOM every frame
/**
* FPS Meter - Returns a function that is used to compute the framerate without the overhead of updating the DOM every frame.
* @author Victor B - www.vitim.us
* @param {element} elm DOM Element to write the framerate
* @param {number} refresh Updates per second of the DOM
* @param {function} callback Function called on every DOM update
* @return {function} Returns a function that will be called inside the loop
*/
function fpsMeter(elm, refresh, callback){
//var elm; //element
@victornpb
victornpb / Stopwatch.js
Created April 23, 2014 04:24
Stopwatch constructor to measure the elapsed time
/** Stopwatch constructor to measure the elapsed time
* @author Victor B - www.vitim.us
*/
function Stopwatch(){
this.running = false;
this.startTimestamp;
this.endTimestamp;
}
Stopwatch.prototype.start = function(){