Skip to content

Instantly share code, notes, and snippets.

View Narayon's full-sized avatar
🛠️

Rui Barbosa Narayon

🛠️
View GitHub Profile
@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 / 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 / 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 / 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: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 / 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: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 / gulpfile.js
Created August 25, 2016 10:05 — forked from jadsalhani/gulpfile.js
Ionic Tutorial
var gulp = require('gulp');
var gutil = require('gulp-util');
var bower = require('bower');
var concat = require('gulp-concat');
var sass = require('gulp-sass');
var minifyCss = require('gulp-minify-css');
var rename = require('gulp-rename');
var sh = require('shelljs');
var uglify = require('gulp-uglify');
var mainBowerFiles = require('main-bower-files');
@Narayon
Narayon / ionic-kill-it.sh
Created January 4, 2017 15:06
Ionic - Kill it with Fire!
rm -rf ./plugins
rm -rf ./node_modules
rm -rf ./www/lib
ionic platform rm android
ionic platform rm ios
npm install
bower install
@Narayon
Narayon / block-scroll.css
Last active April 8, 2018 01:53 — forked from davidgilbertson/block-scroll.css
Don't resize the body when you open a modal
/* the page should not change width as content is loaded */
body {
overflow-y: scroll;
}
/* block scrolling without losing the scroll bar and shifting the page */
/* add this class when a modal is open */
body.block-scroll {
overflow: hidden;
overflow-y: scroll !important;