Skip to content

Instantly share code, notes, and snippets.

View maiquelleonel's full-sized avatar
🤓
This is happy to be useful.

Maiquel Leonel maiquelleonel

🤓
This is happy to be useful.
View GitHub Profile
@maiquelleonel
maiquelleonel / exemplo_kainnan.php
Created January 12, 2012 19:38
Mais ou menos isso
<?php
class Group extends ActiveRecord\Model{
static $has_many = array(
array('users'),
array('posts', 'through' => 'group_info'),
);
}
class User extends ActiveRecord\Model{
static $belongs_to = array(
array('group'),
@maiquelleonel
maiquelleonel / sanitize_chars_SQL
Created August 15, 2012 17:52
A simple way to sanitize columns to make url params
UPDATE TABLE_NAME SET COLUMN = REPLACE(COLUMN,'Š','S');
UPDATE TABLE_NAME SET COLUMN = REPLACE(COLUMN,'š','s');
UPDATE TABLE_NAME SET COLUMN = REPLACE(COLUMN,'Ð','Dj');
UPDATE TABLE_NAME SET COLUMN = REPLACE(COLUMN,'Ž','Z');
UPDATE TABLE_NAME SET COLUMN = REPLACE(COLUMN,'ž','z');
UPDATE TABLE_NAME SET COLUMN = REPLACE(COLUMN,'À','A');
UPDATE TABLE_NAME SET COLUMN = REPLACE(COLUMN,'Á','A');
UPDATE TABLE_NAME SET COLUMN = REPLACE(COLUMN,'Â','A');
UPDATE TABLE_NAME SET COLUMN = REPLACE(COLUMN,'Ã','A');
UPDATE TABLE_NAME SET COLUMN = REPLACE(COLUMN,'Ä','A');
<?php
$tabuada_da_vez = 1;
while ($tabuada_da_vez <= 10) {
echo "Tabuada do ". $tabuada_da_vez . '<br />';
for($i =1; $i <= 10; $i++){
@maiquelleonel
maiquelleonel / changeDate.php
Last active August 29, 2015 14:21
Increments or decrements mintues in a Date string
<?php
function changeDate($strDate, $op, $increment,$format='d/m/Y H:i'){
if(!in_array($op,array('+','-'))){
throw new Execption('The param 2 (operator) must be + or -');
}
if($increment < 0){
$increment *= -1;
@maiquelleonel
maiquelleonel / exemplo_1.sh
Created June 6, 2015 18:28
Exemplo 01 de shell script
#!/bin/bash
for file in $(ls ./logs/"$1"_*); do
if [ $file == "./logs/"$1"_00.csv" ]; then
cabecalho=$(head -1 ./logs/"$1"_00.csv);
continue
fi
touch access_log_users.swp
#!/bin/bash
DIR='./logs/'
ATUAL=$(pwd)
for file in $(ls $DIR"$1"_*); do
cat $file >> "$DIR"olds/"$1"_full.csv
done
cd "$DIR"olds/
split --additional-suffix=.csv -d -l 500 "$1"_full.csv $1"_"
rm -rf "$1"_full.csv
cd $ATUAL
#!/bin/bash
DIR='./logs/'
files="";
for file in $(ls $DIR"$1"_*); do
files=$files" "$file
done
zip -r $1".zip" $files
mv $1".zip" $DIR"olds/"
## exercicio 4
rm -rf $DIR"$1"_*
#0) copiar e descompactar o seguinte arquivo https://dl.dropboxusercontent.com/u/32535093/app.tar.gz
#
#1) adicionar o cabecalho do arquivo de log contendo o titulo das colunas.
# * veirificar o arquivo *_00.csv de cada log
#
#2) criar arquivos de log com 500 linhas, excluindo o cabelçalho
#
#3) compactar os arquivos de log para o formato ".zip" e
# movê-los para a pasta app/log/olds
#
#!/bin/bash
pwd=$(pwd)
cd app/imgs
for file in $(ls ./); do
name=(${file//_/ })
mv $file ${name[1]}"_"${name[2]}
done
#!/bin/bash
pwd=$(pwd)
cd app/imgs
for file in $(ls ./); do
name=(${file//_/ })
new_dir=${name[0]}