Skip to content

Instantly share code, notes, and snippets.

View flaviosilveira's full-sized avatar
:octocat:

Flávio Augusto da Silveira flaviosilveira

:octocat:
View GitHub Profile
<?php
function merge_sort($my_array){
echo "chamou merge_sort\n";
if(count($my_array) == 1 ) {
return $my_array;
}
$mid = count($my_array) / 2;
<?php
$dir = '/Users/flaviosilveira/Dropbox/php-mentors/manuscript';
$result = array();
foreach(scandir($dir) as $file){
switch ($file){
case '.':
case '..':
@flaviosilveira
flaviosilveira / remove-line.sh
Last active January 30, 2019 18:27
Shell script to remove a specific line from files in a directory.
#!/bin/bash
for file in `grep -ril 'pattern-match' . | grep -v 'script'`
do
sed -i '/pattern-match/ d' $file
done
@flaviosilveira
flaviosilveira / crawler.sh
Last active January 20, 2019 01:30 — forked from chenyanzhe/crawler.sh
Gather Geo-Tagged Tweets using Twitter Streaming API | Just change the line 31 to catch tweets from where you want
#/bin/bash
#Function to Encode
# Thanks to https://gist.github.com/cdown/1163649/8a35c36fdd24b373788a7057ed483a5bcd8cd43e
encode() {
local _length="${#1}"
for (( _offset = 0 ; _offset < _length ; _offset++ )); do
_print_offset="${1:_offset:1}"
case "${_print_offset}" in
[a-zA-Z0-9.~_-]) printf "${_print_offset}" ;;
@flaviosilveira
flaviosilveira / popularTimes.js
Created March 16, 2017 01:38
CasperJS Script to grab google popular time
// Inicia Casper, simulando User Agent
var casper = require('casper').create({
pageSettings: {
userAgent: 'User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.120 Safari/537.36'
}
}
);
// Vai até o endereço
casper.start('https://www.google.com.br/search?q=tuk%20tuk%20curitiba&*', function() {
@flaviosilveira
flaviosilveira / delete_old_branchs.sh
Created September 14, 2015 02:09
Delete Old Branches
#!/bin/sh
date=2015-01-01
for branch in $(git branch -a | sed 's/^\s*//' | sed 's/^remotes\///' | grep -v 'master$'); do
if [ $(git log $branch --since $date | wc -l) -eq 0 ]; then
# echo "DELETAR $branch"
git push --delete origin $(echo $branch | sed 's/^\s*//' | sed 's/^origin\///')
#else
# echo "NAO $branch"
@flaviosilveira
flaviosilveira / gist:87bc90e3f0f495bd3fa1
Created May 26, 2014 00:29
JavaScript - Array Explode
var value = { "aaa": "111", "bbb": "222", "ccc": "333" };
var blkstr = [];
$.each(value, function(idx2,val2) {
var str = idx2 + ":" + val2;
blkstr.push(str);
});
console.log(blkstr.join(", "));
<?php
function img_resize($ini_path, $dest_path, $params = array())
{
$width = !empty($params['width']) ? $params['width'] : null;
$height = !empty($params['height']) ? $params['height'] : null;
$constraint = !empty($params['constraint']) ? $params['constraint'] : false;
$rgb = !empty($params['rgb']) ? $params['rgb'] : 0xFFFFFF;
$quality = !empty($params['quality']) ? $params['quality'] : 100;
$aspect_ratio = isset($params['aspect_ratio']) ? $params['aspect_ratio'] : true;
<?php
$image = $_FILES["file"];
if(preg_match("/^image\/(pjpeg|jpeg|png|gif|bmp)$/", $image["type"]))
{
// Mime Type
preg_match("/\.(gif|bmp|png|jpg|jpeg){1}$/i", $image["name"], $ext);
// File name
$name = md5(uniqid(time())) . "." . $ext[1];