Skip to content

Instantly share code, notes, and snippets.

View luanlmd's full-sized avatar

Luan Almeida luanlmd

View GitHub Profile
<?php
class ArrayMixer
{
function __construct($options)
{
$this->options = $options;
$this->result = array();
}
function go($arr, $x)
@luanlmd
luanlmd / email.php
Created April 16, 2010 18:27
Sending email with PEAR Mail class
<?php
include("Mail.php");
//$headers['Reply-to'] = "$name <$email>";
$headers['From'] = 'username@gmail.com';
$headers['Subject'] = "Test";
$headers['Content-Type'] = "text/plain; charset=utf-8";
$recipients = 'luckyguy@gmail.com';
$body = 'Something';
@luanlmd
luanlmd / varnimate.js
Created May 28, 2010 02:11
Varnimate
function varnimate(obj,props,duration,start)
{
var now = new Date().getTime();
var atual = new Date().getTime();
//console.log(atual);
if (start+duration <= atual)
{
for (p in props)
{
obj[p] = props[p]
@luanlmd
luanlmd / backup_pgsql.sh
Created November 3, 2010 21:15
Backup PostgreSQL Databases
#!/bin/bash
LIST=$(/usr/bin/psql -l | /usr/bin/awk '{ print $1}' | grep -vE '^-|^\(|^List|^N[o|a]me|template[0|1]')
for d in $LIST
do
echo "Backuping: " $d
pg_dump -i -h 127.0.0.1 -p 5432 -U postgres -F t -b -f "/backup/backup/$d.backup" $d
tar -zcf /backup/backup/$d.tar.gz -C / backup/backup/$d.backup
rm /backup/backup/$d.backup
@luanlmd
luanlmd / backup_rsync.sh
Created November 3, 2010 21:17
Sync backups
#!/bin/bash
/usr/bin/rsync --progress -avhz --delete --update /folder/from/ user@host:~/folter/to/ --ignore-errors
@luanlmd
luanlmd / backup_compact.sh
Created November 7, 2010 20:27
Compact folders after sync
cd /home/secombkp/backup/
DATE=`/bin/date +%Y-%m-%d`
for FILE in *
do
FILENAME=$FILE"-"$DATE".tar.gz"
echo "Creating" $FILENAME
tar -zcf ../backup_history/$FILENAME $FILE
done
@luanlmd
luanlmd / etag.php
Created November 18, 2010 20:59
Etag test in PHP
<?php
ob_start();
?>
<!DOCTYPE html>
<html>
<head>
<title>Etag test</title>
</head>
<body>
@luanlmd
luanlmd / aloneInTheNetwork.php
Created December 2, 2010 19:16
Check if the PC is alone in the network
#!/usr/bin/php5 -q
<?php
$broadcast = "10.55.2.255";
$ignore = array('10.55.2.240','10.55.2.66');
$ignore = implode('|',$ignore);
$string = "ping -b {$broadcast} -c 2 | grep 'icmp_req=1' | grep -vE '{$ignore}'";
$result = shell_exec($string);
if (trim($result))
{
exit('false');
@luanlmd
luanlmd / transmissionLimit.php
Created December 3, 2010 18:55
Set limits for transmission if there is another PCs in the Network or... not
#!/usr/bin/php5 -q
//require https://gist.github.com/725875
<?php
while(true)
{
$alone = shell_exec('./aloneInTheNetwork.php');
if ($alone == 'true')
{
echo 'go go go!';
echo shell_exec('transmission-remote localhost:9091 -AS');
@luanlmd
luanlmd / apt.conf
Created July 19, 2011 13:40
apt-cacher client config
# /etc/apt/apt.conf
Acquire {
HTTP::Proxy "http://10.55.2.224:3142";
FTP::Proxy "http://10.55.2.224:3142";
}