Skip to content

Instantly share code, notes, and snippets.

View Narayon's full-sized avatar
🛠️

Rui Barbosa Narayon

🛠️
View GitHub Profile
@Narayon
Narayon / gist:5f2cbb34594665abf3c81cc56eb7eed4
Created April 22, 2016 19:06
AngularJS 1.x Performance Tips
In general, keep the digest cycle slim, avoiding the creation of watchers, when possible.
Some tips:
- ng-bind instead of {{expressions}}
- use bind once: ng-bind="::expression" or {{::expression}}
- avoid ng-repeat, but if necessary, use track by ...
- use small directives, with new or nested scope, instead of a monolithic scope
- use local events and $digest/$apply(when needed), to prevent running the digest cycle globally, for every event
- use $digest instead of $apply, when changes only affect children
- don't use filters in the DOM, use pre filtered data instead
- don't use true/false DOM logic in the controller
@Narayon
Narayon / analyse_watchers.js
Last active April 8, 2018 02:52 — forked from DTFagus/analyse_watchers.js
Bookmarklet to analyse angular watchers
javascript: (function() {
var root = angular.element(document.getElementsByTagName('html'));
var watchers = [];
var attributes = [];
var attributes_with_values = [];
var elements = [];
var elements_per_attr = [];
var scopes = [];
@Narayon
Narayon / gist:ecfe2abecf76debe9937
Last active April 8, 2018 02:52 — forked from jennimckinnon/functions.php
Wordpress: Add Google Font
function google_fonts() {
$query_args = array(
'family' => 'Open+Sans:400,700|Oswald:700'
'subset' => 'latin,latin-ext',
);
wp_register_style( 'google_fonts', add_query_arg( $query_args, "//fonts.googleapis.com/css" ), array(), null );
}
add_action('wp_enqueue_scripts', 'google_fonts');
@Narayon
Narayon / gist:6c56a8591c7cbb2454ab
Last active April 8, 2018 02:52 — forked from jameskoster/functions.php
WooCommerce: dequeue css (2.1+)
// Remove each style one by one
add_filter( 'woocommerce_enqueue_styles', 'jk_dequeue_styles' );
function jk_dequeue_styles( $enqueue_styles ) {
unset( $enqueue_styles['woocommerce-general'] ); // Remove the gloss
unset( $enqueue_styles['woocommerce-layout'] ); // Remove the layout
unset( $enqueue_styles['woocommerce-smallscreen'] ); // Remove the smallscreen optimisation
return $enqueue_styles;
}
// Or just remove them all in one line
@Narayon
Narayon / gist:556f42e012b2645b7ae9
Created October 8, 2015 09:09
CSS: Text Display Optimization
html {
-moz-osx-font-smoothing: grayscale;
-webkit-font-smoothing: antialiased;
text-rendering: optimizeLegibility;
}
@Narayon
Narayon / random.js
Last active April 8, 2018 02:52 — forked from kerimdzhanov/random.js
Javascript: random number in a specific range
// MIT License
// @return {float} a random number between min and max
function getRandom(min, max) {
return Math.random() * (max - min) + min;
}
// @return {integer} a random int between min and max
function getRandomInt(min, max) {
return Math.floor(Math.random() * (max - min + 1) + min);
@Narayon
Narayon / check-default-lang.php
Last active April 9, 2018 22:09
PHP: check browser default language
<?php
function prefered_language( $available_languages, $http_accept_language = 'auto' ) {
if ( 'auto' == $http_accept_language ) {
// $http_accept_language = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
$http_accept_language = isset( $_SERVER['HTTP_ACCEPT_LANGUAGE'] ) ? $_SERVER['HTTP_ACCEPT_LANGUAGE'] : '';
}
preg_match_all( '/([[:alpha:]]{1,8})(-([[:alpha:]|-]{1,8}))?' . '(\s*;\s*q\s*=\s*(1\.0{0,3}|0\.\d{0,3}))?\s*(,|$)/i', $http_accept_language, $hits, PREG_SET_ORDER );
$bestlang = $available_languages[0];
@Narayon
Narayon / jQuery-preloadFunction
Last active April 8, 2018 02:52 — forked from simaovergalho/jQuery-preloadFunction
jQuery: Preload Images, CSS and JS
/*!
* $.preload() function for jQuery – http://mths.be/preload
* Preload images, CSS and JavaScript files without executing them
* Script by Stoyan Stefanov – http://www.phpied.com/preload-cssjavascript-without-execution/
* Slightly rewritten by Mathias Bynens – http://mathiasbynens.be/
* Note that since this script relies on jQuery, the preloading process will not start until jQuery has finished loading.
*/
jQuery.preload = function(array) {
var length = array.length,
@Narayon
Narayon / PHP-normalize_global_path
Last active April 8, 2018 02:52 — forked from simaovergalho/PHP-normalize_global_path
PHP: global vars for normalizing the ROOT and HTTP paths of the app.
<?php
// a.php: assuming this included everywhere at very first line
// and located in root directory
// preferable, define a constant instead of variable, cos it
// may used in functions directly without "global $ROOT";
// to use for "include"
define('ROOT', __DIR__); // for PHP >= 5.3
define('ROOT', realpath(dirname(__FILE__))); // for PHP < 5.3
// to use for "src,href"
@Narayon
Narayon / Javascript-jQuery_replacer
Last active April 8, 2018 02:52 — forked from simaovergalho/Javascript-jQuery_replacer
Javascript: Stop Using jQuery
<div class="container">
<ul>
<li id="pink">Pink</li>
<li id="salmon">Salmon</li>
<li id="blue">Blue</li>
<li id="green">Green</li>
<li id="red">Red</li>
</ul>
</div>