Skip to content

Instantly share code, notes, and snippets.

@henriquemoody
henriquemoody / registry.js
Created August 10, 2011 19:49
Implementação de Registry em javascript.
/**
* Implementação de Registry em javascript.
*
* @author Henrique Moody
*/
var Registry = new function Registry () {
// Dados no registry
var _data = new Array();
@henriquemoody
henriquemoody / remove-php-short-tags.sh
Created August 23, 2011 13:57
Remove PHP short tags
#! /bin/sh
ignore='\.svn';
for file in $(egrep '<\?$' -Rn --include=*.php . | egrep -v "${ignore}" | cut -d':' -f1 | sort | uniq);
do
sed -ri 's/<\?$/<?php/g' ${file};
done;
for file in $(egrep '<\?([^px=])' -Rn --include=*.php . | egrep -v "${ignore}" | cut -d':' -f1 | sort | uniq);
@henriquemoody
henriquemoody / php-entity-rename.sh
Created August 23, 2011 17:50
[php-entity-rename] Rename a PHP class or interface.
#!/bin/bash
oldName=$1
newName=$2
pattern="(new|class|extends|interface|implements) +(\b${oldName}\b)";
egrep -i "${pattern}" -Rn --include=*.php --exclude=*.svn* . | cut -d':' -f1 | sort | uniq | xargs sed -ri "s/${pattern}/\1 ${newName}/gi";
pattern="(\b${oldName}\b)::";
egrep -i "${pattern}" -Rn --include=*.php --exclude=*.svn* . | cut -d':' -f1 | sort | uniq | xargs sed -ri "s/${pattern}/${newName}::/gi";
@henriquemoody
henriquemoody / pdo.php
Created November 18, 2011 01:27
Test of PDO attributes
<?php
$pdo = new PDO("sqlite:/tmp/pdo.db");
$attributes = array(
"AUTOCOMMIT",
"ERRMODE",
"CASE",
"CLIENT_VERSION",
"CONNECTION_STATUS",
"ORACLE_NULLS",
"DRIVER_NAME",
@henriquemoody
henriquemoody / watcher.js
Created November 18, 2011 18:44
Watcher in javascript.
var Watcher = function ()
{
var _interval = 1000;
var _running = false;
var _callback = function ()
{
// Just a callback
@henriquemoody
henriquemoody / strings.php
Created December 22, 2011 12:32
Camel case to separator and vice-versa.
<?php
/**
* @param string $string
* @param string $separator
* @return string
*/
function camelCaseToSeparator($string, $separator = '-')
{
return preg_replace('/(?<=[a-z])([A-Z])/', $separator . '$1', $string);
@henriquemoody
henriquemoody / php-entity-finder.sh
Last active September 28, 2015 23:08
[php-entity-finder] Find PHP classes or interfaces.
#!/usr/bin/env bash
# Usage: {script} ENTITY
#
declare ENTITIES=${1}
find_entity()
{
local entity=${1}
local spaces="${2}"
@henriquemoody
henriquemoody / find-and-delete.sh
Created January 6, 2012 13:53
Find all occurrences of the files of DIR into other files and delete then
#!/bin/bash
HELP="Usage: $(basename ${0}) DIR
or: $(basename ${0}) --help
Find all occurrences of the files of DIR into other files and delete then if
there is no occurrence.
--help display this help and exit
Exemplos:
@henriquemoody
henriquemoody / symlink-to-target.sh
Created February 23, 2012 22:10
Convert a symbolic link to a copy of its target
@henriquemoody
henriquemoody / rename-seq
Last active October 1, 2015 01:38
[rename-seq] Rename files in sequence
#!/usr/bin/env bash
# Usage: {script} [--debug|-d] DIRECTORY [ PREFIX ]
#
# --debug, -d Run script in debug mode
# --help, -h Displays this help
#
# Report bugs to Henrique Moody <henriquemoody@gmail.com>
#
declare DEBUG_MODE=0