Skip to content

Instantly share code, notes, and snippets.

View ptomasroos's full-sized avatar

Tomas Roos ptomasroos

View GitHub Profile
@ptomasroos
ptomasroos / gist:39070d1799addecd5b3288e5bc85068e
Created November 29, 2017 12:12
uBlock GPT base64 object
(function() {
var p;
// https://developers.google.com/doubleclick-gpt/reference
var noopfn = function() {;
}.bind();
var noopthisfn = function() {
return this;
};
var noopnullfn = function() {
return null;
@ptomasroos
ptomasroos / gist:9cd64ad6513fca9ae170028ecbbd7ffd
Created January 30, 2017 12:19
Prevent slow console logging in RN production apps
// this guards against console usage in production builds since
// babel transform of remove console won't work with react-native preset
if (!__DEV__) {
['assert', 'clear', 'count', 'debug', 'dir', 'dirxml', 'error', 'exception',
'group', 'groupCollapsed', 'groupEnd', 'info', 'log', 'profile', 'profileEnd',
'table', 'time', 'timeEnd', 'timeStamp', 'trace', 'warn'].forEach(
(methodName) => {
console[methodName] = () => { /* noop */ };
});
}
componentWillReceiveProps(nextProps) {
if (nextProps.lastRequestedUserLocationAt > this.props.lastRequestedUserLocationAt) {
this.centerMapToUser(nextProps.currentLocation);
}
if (nextProps.lastUpdated > this.props.lastUpdated) {
const markers = this.createMarkersForLocations(nextProps);
if (markers && Object.keys(markers)) {
const clusters = {};
@ptomasroos
ptomasroos / remove.txt
Created September 11, 2015 13:30
Remove program entries in i3 dmenu
To remove a program in the i3 dmenu just pipe the result from dmenu_path in the /usr/bin/dmenu_run
dmenu_path | awk '!/zsh/' | .......
would remove zsh.
@ptomasroos
ptomasroos / gist:8dc1cf21271f5c17cea1
Created January 21, 2015 09:49
Avoid extra request for fav.icon
<link rel="shortcut icon" href="data:image/x-icon;," type="image/x-icon">
@ptomasroos
ptomasroos / ServerRender
Last active August 29, 2015 14:07
Yahoo flux flow
https://www.websequencediagrams.com/
title First navigation
opt server response
Browser->Express: GET /url
Express->Context: executeAction(navigate({ path: /url }))
Context->NavigateAction: Invoke
NavigateAction->ModelStores: Dispatch 'CHANGE_ROUTE_SUCCESS'
// base controller
define(['lazoCtl'], function (Ctl) {
'use strict';
return Ctl.extend({
index: function (options) {
this.loadModel('session', {
success: function (model) {
define(['lazoApp'], function (App) {
'use strict;
return App.extend({
initialize: function (callback) {
var html = '<!--[if IE 8]> <html lang="en" class="ie8"> <![endif]--><html lang="en">';
LAZO.app.setHtmlTag(html);
LAZO.app.setBodyClass('some-class another-class');
// backs user model
define(['lazoSyncher'], function (LazoSyncher) {
return LazoSyncher.extend({
authenticate: function (credentials, options) {
// authenticate user using credentials
// you can call options.success or options.error
// update the user model, auth token, etc.
}
// in a controller
// you can either update the collection directly or send
// a message in the LAZO.app dispatcher
// (you can use a controller dispatcher if you want to be more granular)
var socket = io();
var self = this;
var notifications = this.ctx.collections.notifications;
// three different approaches to re-rendering a badge count
socket.on('notification', function (msg) {