Skip to content

Instantly share code, notes, and snippets.

View squiter's full-sized avatar

Brunno dos Santos squiter

View GitHub Profile
@squiter
squiter / followings.rb
Created February 5, 2014 21:27
Followers in Rails
class Followings < ActiveRecord::Base
attr_accessible :user_id, :follower_id
belongs_to :user
belongs_to :follower, class_name: 'User'
belongs_to :following, class_name: 'User', foreign_key: :user_id
validates_uniqueness_of :user_id, scope: :follower_id
end
@squiter
squiter / gist:cf4e474b8b51251c5085
Created April 22, 2015 01:47
Mod 11 - Módulo 11
def mod11(number, total)
as_string = number.to_s
sub = as_string.length
value = 0
max = total
sub.times do |t|
value += as_string[t].to_i * max
max = max - 1
end
@squiter
squiter / includes.php
Created May 26, 2011 20:30
Show all include pages
<?php
$included_files = get_included_files();
foreach ($included_files as $filename) {
echo "$filename\n";
}
?>
@squiter
squiter / check_http.php
Created June 13, 2011 20:59
Get http response code from a URL
<?php
/*
* Check HTTP Header Response
* Author: Brunno dos Santos
* Version: 1.0
* Usage: run php check_http.php www.yoursite.com
*/
$ch = curl_init($argv[1]);
curl_setopt($ch, CURLOPT_NOBODY, 1);
@squiter
squiter / migration.sh
Created October 6, 2011 13:49
Import MySQL dump to a database
#!/bin/bash
##################################################
#### Script para importar dumps de MySQL #########
##################################################
# Configurações
# Onde está seu MySQL?
MySQL="/opt/local/bin/mysql5"
@squiter
squiter / migration.sh
Created October 6, 2011 14:23
Import MySQL dump to a database using parameters
#!/bin/bash
##################################################
#### Script para importar dumps de MySQL #########
#### #########
#### Instruções: #########
#### Sempre passar os parametros #########
#### -u Nome de usuário #########
#### -h Hostname #########
#### -d Nome do Banco #########
@squiter
squiter / gist:1942527
Created February 29, 2012 17:09
List encoding of all files in a folder
for file in *.php; do file --mime $file;
done
@squiter
squiter / Asset.sql
Created April 3, 2012 12:19
Mudando a URL do Wordpress
UPDATE wp_options SET option_value = replace(option_value, 'http://__www.old-site.com__', 'http://__www.new-site.com__') WHERE option_name = 'home' OR option_name = 'siteurl';
UPDATE wp_posts SET guid = replace(guid, 'http://__www.old-site.com__','http://__www.new-site.com__');
UPDATE wp_posts SET post_content = replace(post_content, 'http://__www.old-site.com__', 'http://__www.new-site.com__');
@squiter
squiter / Asset.rb
Created April 3, 2012 20:25
Take a screenshot
# first install 'selenium-webdriver'gem
require 'selenium-webdriver'
width = 800
height = 600
driver = Selenium::WebDriver.for :firefox
driver.navigate.to 'http://localhost:3000'
driver.execute_script %Q{
window.resizeTo(#{width}, #{height});
}
driver.save_screenshot('/tmp/screenshot.png')
@squiter
squiter / 000-default
Created July 5, 2012 20:19
[Abstraindo.com] Vagrant de forma simples - Esses exemplos foram utilizados no post do abstraindo, os arquivos finais irão ficar em outo gist.
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /vagrant/sites
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>