Skip to content

Instantly share code, notes, and snippets.

View tilomitra's full-sized avatar
👋

Tilo Mitra tilomitra

👋
View GitHub Profile
@WalrusSoup
WalrusSoup / LazyLoadIntercom.js
Created October 29, 2021 17:58
Lazy load intercom on scroll to help speed up PageSpeed Insights
// replace YOUR_INTERCOM_URL_HERE with your app_id
var intercomLoader = function() {
(function(){var w=window;var ic=w.Intercom;if(typeof ic==="function"){ic('reattach_activator');ic('update',w.intercomSettings);}else{var d=document;var i=function(){i.c(arguments);};i.q=[];i.c=function(args){i.q.push(args);};w.Intercom=i;var l=function(){var s=d.createElement('script');s.type='text/javascript';s.async=true;s.src='https://widget.intercom.io/widget/YOUR_INTERCOM_URL_HERE';var x=d.getElementsByTagName('script')[0];x.parentNode.insertBefore(s, x);};if(document.readyState==='complete'){l();}else if(w.attachEvent){w.attachEvent('onload',l);}else{w.addEventListener('load',l,false);}}})();
window.Intercom('boot', {
app_id: 'YOUR_INTERCOM_URL_HERE'
})
window.removeEventListener('scroll', intercomLoader);
}
window.addEventListener('scroll', intercomLoader);
@smeijer
smeijer / parse-es6-template.js
Last active March 13, 2024 07:53
ES6 template string parser
function get(path, obj, fb = `$\{${path}}`) {
return path.split('.').reduce((res, key) => res[key] || fb, obj);
}
function parseTpl(template, map, fallback) {
return template.replace(/\$\{.+?}/g, (match) => {
const path = match.substr(2, match.length - 3).trim();
return get(path, map, fallback);
});
}
@tilomitra
tilomitra / animations.css
Last active March 27, 2023 13:55
Common CSS Infinite Animations (pulsate, opacityPulse, alertPulse, rotating).
/* Make the element pulse (grow large and small slowly) */
/* Usage
.myElement {
animation: pulsate 1s ease-out;
animation-iteration-count: infinite;
opacity: 1;
}
*/
@-webkit-keyframes pulsate {
0% {-webkit-transform: scale(0.1, 0.1); opacity: 0.0;}
package com.dotp;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import com.facebook.react.LifecycleState;
import com.facebook.react.ReactInstanceManager;
@devinivy
devinivy / stubQueryMethod.js
Last active September 29, 2020 10:31 — forked from wxactly/stubQueryMethod.js
Sails.js: Stub Waterline query method with Sinon.js
var util = require('util');
var _ = require('lodash');
var sinon = require('sinon');
/**
* Replaces a query method on the given model object with a stub. The query
* will still operate on a callback, and allow full access to waterline's
* deferred object. However, the query will not cause any I/O and instead
* will immediately resolve to the given result.
*
@astashov
astashov / gist:b90c0888c25272399262
Last active October 13, 2016 16:37
Rebound.js-like spring animation in SCSS/SASS
$solver_timestamp_sec: 0.01;
// Rebound.js-like spring animations in SCSS.
// There is a bunch of functions, which helps generating keyframes for you spring
// animations, if you (like me) really want to avoid doing that in JavaScript.
//
// It only generates values for one spring, with given friction, tension and end value
// (i.e. it doesn't support spring systems)
// Friction and tension are matched to the values used in Origami, so you can use whatever
// your designers put in a Quartz Composer file in "Bouncy Animation" blocks :)
> var css = rework('').use(pureGrids.units(8)).toString();
undefined
> console.log(css);
.pure-u-1-8,
.pure-u-2-8,
.pure-u-1-4,
.pure-u-3-8,
.pure-u-4-8,
.pure-u-1-2,
.pure-u-5-8,
@triptych
triptych / auto.txt
Last active December 19, 2015 16:49
automated yeti testing functional tests
cd yui3
yui3> selleck
yui3> cd build_docs
build_docs> cp -R ../build .
build_docs> yeti `../src/common/node/selleck_list.js`
----
to test one file:
@lsmith
lsmith / gist:4272500
Created December 12, 2012 23:04
Potential patch for 'tap' synthetic event's notifier custom event to allow e.preventDefault() or e.stopPropagation() to have that effect on the subsequent 'click' event.
notifier.handle.evt.fire = function (e) {
var subs = this._subscribers.concat(this._afters),
args = Y.Array(arguments, 0, true),
i, len, halt;
for (i = 0, len = subs.length; i < len; ++i) {
halt = subs[i].notify(args, this);
// stopImmediatePropagation
if (halt === false || e.stopped > 1) {
@tilomitra
tilomitra / gist:4179224
Created November 30, 2012 22:43
YUI Weekly Nov 30