Skip to content

Instantly share code, notes, and snippets.

View BernardoSilva's full-sized avatar
🏠
Working from home

Bernardo Vieira da Silva BernardoSilva

🏠
Working from home
View GitHub Profile
@BernardoSilva
BernardoSilva / filterDropDown.js
Last active December 12, 2015 04:38
jQuery basic logic for a search as the user type
function filter_users_dropdown() {
search = $('#from').val().toLowerCase();
$('#users-dropdown li').each(function(index) {
var value = $(this).text().toLowerCase();
n = value.search( search );
$('.myElements').each(function() {
var elem = $(this);
// Save current value of element
elem.data('oldVal', elem.val());
// Look for changes in the value
elem.bind("propertychange keyup input paste", function(event){
// If value has changed...
if (elem.data('oldVal') != elem.val()) {
@BernardoSilva
BernardoSilva / .htaccess
Created February 5, 2013 20:03
.htaccess for Codeigniter to avoid index.php and force www. before any URL
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} !^$
# BEGIN force www before URL
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
# END for www on URL
@BernardoSilva
BernardoSilva / animationframe
Created July 18, 2013 01:07
Base to create an animation frame in browser
window.requestAnimFrame = (function(callback) {
return window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || window.oRequestAnimationFrame || window.msRequestAnimationFrame ||
function(callback) {
window.setTimeout(callback, 1000 / 60);
};
})();
function animate() {
var canvas = document.getElementById('canvas_1');
var context = canvas.getContext('2d');
@BernardoSilva
BernardoSilva / composer_mamp_osx.sh
Created September 5, 2013 16:13
These are the steps to install composer on MAC OS X to work with MAMP php
# Global composer install for MAMP Users on OSX
# http://getcomposer.org/doc/00-intro.md#globally
# For PHP 5.4 Use:
# alias php=/Applications/MAMP/bin/php/php5.4.4/bin/php;
alias php=/Applications/MAMP/bin/php/php5.3.6/bin/php;
curl -sS https://getcomposer.org/installer | php;
mv composer.phar /usr/local/bin/composer;
composer help;
@BernardoSilva
BernardoSilva / set_mamp_php.sh
Created September 5, 2013 16:25
These are the steps to change between the PHP that comes with OSX installation for the MAMP php version you want to run by default when you write php on command line
#this is a way to change the default php to MAMP php version you want
#if you do `which php` you eill see: /usr/bin/php that is the php that comes with OSX installation
which php
#do this to export the path to you .profile ou .bash_profile
export PATH=/Applications/MAMP/bin/php/php5.4.4/bin:$PATH
#then run this command to update the path
source ~/.bash_profile
@BernardoSilva
BernardoSilva / JS_subClass_example.js
Created September 11, 2013 23:02
example of javascript class definition and Inheritance
// JavaScript Class Definition and Inheritance
function BaseClass() {
//BaseClass constructor code goes here
}
BaseClass.prototype.getName = function() {
return "BaseClass";
}
function SubClass() {
@BernardoSilva
BernardoSilva / standard_php_autoloader
Created March 2, 2014 19:21
example os a standard php autoloader following the PSR-0
<?php
function autoload($className)
{
$className = ltrim($className, '\\');
$fileName = '';
$namespace = '';
if ($lastNsPos = strrpos($className, '\\')) {
$namespace = substr($className, 0, $lastNsPos);
$className = substr($className, $lastNsPos + 1);
@BernardoSilva
BernardoSilva / .htaccess
Created March 13, 2014 21:08
this is a way to make zf2 work on a shared hosting
#make ZF2 work on shared hosting using this htaccess
#SetEnv ZF2_PATH /home/username/zf2lib
RewriteEngine On
RewriteRule ^\.htaccess$ - [F]
RewriteCond %{REQUEST_URI} =""
RewriteRule ^.*$ /public/index.php [NC,L]
RewriteCond %{REQUEST_URI} !^/public/.*$
RewriteRule ^(.*)$ /public/$1
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^.*$ - [NC,L]
@BernardoSilva
BernardoSilva / install_mongoDb
Last active August 29, 2015 14:04
Install specific version of MongoDb on Ubuntu
First you have to download the 32bit or 64bit Linux binaries from here and unzip the contents to /usr/local.
# cd /tmp
# curl -O http://downloads.mongodb.org/linux/mongodb-linux-i686-2.4.9.tgz
# sudo tar -zxf /tmp/mongodb-linux-i686-2.4.9.tgz -C /usr/local
Then you need to configure some symbolic links.