Skip to content

Instantly share code, notes, and snippets.

View Narayon's full-sized avatar
🛠️

Rui Barbosa Narayon

🛠️
View GitHub Profile
@Narayon
Narayon / index.php
Last active April 8, 2018 01:52 — forked from simaovergalho/index.php
PHP: prevent direct folder/file access
if( ! defined('ABSPATH') ) {
header( 'Status: 403 Forbidden' );
header( 'HTTP/1.1 403 Forbidden' );
exit;
}
//OR
if ( ! defined('ABSPATH') ) { die('-1'); }
<?php
/**
* Disable Emojis
*
* @package Package
* @subpackage Package/SubPackage
* @copyright Copyright (c) 2014, Your Name
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
* @since 0.0.1
* @author Your Name <email@domain.com>
@Narayon
Narayon / private-members.js
Last active April 8, 2018 01:52 — forked from simaovergalho/private-members.js
Javascript: Embed Private Members Into an Object
//reference to: http://code.tutsplus.com/tutorials/javascript-how-to-embed-private-members-into-an-object--cms-24287
var createProperty = function (obj, prop) {
var currentValue = obj[prop];
Object.defineProperty(obj, prop, {
get: function () { return currentValue; },
set: function (value) {
currentValue = value;
},
enumerable: true,
configurable: true
@Narayon
Narayon / JS-Module_pattern.js
Last active April 8, 2018 01:52 — forked from simaovergalho/JS-Module_pattern.js
Javascript: Module Pattern
var UTIL = (function (parent, $) {
var my = parent.ajax = parent.ajax || {};
my.get = function (url, params, callback) {
// ok, so I'm cheating a bit :)
return $.getJSON(url, params, callback);
};
// etc...
@Narayon
Narayon / JS-rAF.js
Last active April 8, 2018 01:52 — forked from simaovergalho/JS-rAF.js
Javascript: Request Animation Frame
// http://paulirish.com/2011/requestanimationframe-for-smart-animating/
// http://my.opera.com/emoller/blog/2011/12/20/requestanimationframe-for-smart-er-animating
// requestAnimationFrame polyfill by Erik Möller. fixes from Paul Irish and Tino Zijdel
// MIT license
(function() {
var lastTime = 0;
var vendors = ['ms', 'moz', 'webkit', 'o'];
@Narayon
Narayon / add_image_size.php
Last active April 8, 2018 01:53
Wordpress: add image size
<?php
//set custom sizes
if ( function_exists( 'add_image_size' ) ) {
add_image_size( 'category-thumb', 300, 9999 ); //300 pixels wide (and unlimited height)
add_image_size( 'homepage-thumb', 220, 180, true ); //(cropped)
}
//rename custom sizes for the Dashboard, with translation
add_filter('image_size_names_choose', 'PREFIXIT_image_sizes');
function PREFIXIT_image_sizes($sizes) {
@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 / pubsub.js
Created February 24, 2017 19:17
Angular v1 Pub-Sub
// an example channel service that lets consumers
// subscribe and publish for nuclear reactor meltdowns
var CoreReactorChannel = function($rootScope) {
// local constants for the message ids.
// these are private implementation detail
var ELEVATED_CORE_TEMPERATURE_MESSAGE = "elevatedCoreMessage";
// publish elevatedCoreTemperature
@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;
@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