Skip to content

Instantly share code, notes, and snippets.

View keblodev's full-sized avatar
🎩

Keblo keblodev

🎩
View GitHub Profile
@keblodev
keblodev / fps.js
Last active January 20, 2021 11:41
Simple fps counter built with React on Hooks
import React, { useState, useEffect } from "react";
export default function() {
let [frameTimeState, setFrameTimeState] = useState({
fps: 0,
// better use performance.now()
// but some static generators like gatsby
// might have problems with that
lastStamp: Date.now(),
@keblodev
keblodev / timer.js
Created July 20, 2019 06:07
Simple React on Hooks timer component
import React, { useState, useEffect } from "react";
export default function({isDone = false}) {
let [startDate] = useState(new Date());
let [newDate, setNewDate] = useState(new Date());
useEffect(() => {
const timer = !isDone && setTimeout(()=>{
setNewDate(new Date());
@keblodev
keblodev / fetchConstruct.js
Last active February 10, 2019 05:21
a generic wrapper around any react-redux external api call that provides full error handling and event dispatching
export const GENERIC_PREFETCH_CALL = "GENERIC_PREFETCH_CALL";
export const GENERIC_FETCH_SUCCESS_CALL = "GENERIC_FETCH_SUCCESS_CALL";
export const GENERIC_FETCH_FAIL_CALL = "GENERIC_FETCH_FAIL_CALL";
export const handleSuccessError = function(response){
return response.status !== 200 ? response.json().then(error => Promise.reject(error)) : response.json();
}
export const fetchConstruct = function({
url, // required
@keblodev
keblodev / autoprefixer.scss
Created February 9, 2016 21:34
sass autoprefixer method
/// autoprefixer method
/// ---
/// @access public
/// ---
/// @param {string|rulename} $ruleName - rule name
/// ---
/// @param {string|rule} $ruleValue - rule value
@mixin autoprefixer($ruleName, $ruleValue) {
-ms-#{$ruleName}: $ruleValue;
-moz-#{$ruleName}: $ruleValue;
@keblodev
keblodev / extend
Created June 1, 2015 02:35
simple extend
//simpleExtend
var extend = function(targetObj, extendWithObj) {
'use strict';
for (var key in extendWithObj) {
if (extendWithObj.hasOwnProperty(key)) {
targetObj[key] = extendWithObj[key];
}
}
return targetObj;
@keblodev
keblodev / EventEmmiterClassSpec
Created June 1, 2015 00:46
Tests for EventEmmiterClass
//////////////////////// EventEmitter tests
console.info(" --- TESTING START \n");
//textObjClass
var SomeObjClass = function() {
'use strict';
var _someObjClass = {
events: {
@keblodev
keblodev / EventEmitterClass
Created June 1, 2015 00:44
EventEmitterClass: addEventListener and trigger for any custom object
/*
* EventEmitterClass gist
*
* Description: with this class you can add custom events listening/triggering to any custom object
*
* usage: just inherit/extend your custom object with this class's
*
* addEventListener(eventName: {String}, callback: {Function}, optional_context: {Object})
*
* removeEventListener(eventName: {String} || callback: {Function}, callback: {Function}, removeAllForThisEvent: {Boolean})
@keblodev
keblodev / gist:8a10e92686ad6cb9cde0
Created April 24, 2015 00:34
smooth calculate method from value to value
var smoothCalcFromTo = (function () {
var timer;
var easing_pats = {
// accelerating from zero velocity
'ease_in_quad' : function(time) { return time * time; },
// decelerating to zero velocity
'ease_out_quad' : function(time) { return time * (2 - time); },
// acceleration until halfway, then deceleration
'ease_in_out_quad' : function(time) { return time < 0.5 ? 2 * time * time : -1 + (4 - 2 * time) * time; },