Skip to content

Instantly share code, notes, and snippets.

View chebyte's full-sized avatar
🤡
smile

maurotorres chebyte

🤡
smile
View GitHub Profile
@chebyte
chebyte / custom_social_url_validator.rb
Last active December 17, 2015 03:09
custom social url validator for rails
#lib/validators/social_url_validator.rb
class SocialUrlValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
value = smart_add_scheme_url_to record, attribute, value
case attribute
when :facebook
record.errors.add attribute, (options[:message] || "not a valid domain") unless
value =~ /((http|https):\/\/)?(www[.])?facebook.com\/.+/i
when :twitter
@chebyte
chebyte / Nginx - Unicorn
Last active December 15, 2015 19:39 — forked from keikubo/README.md
Nginx + Unicorn for Rails on Rackhub
=========
## Description:
This script enables you to launch your Rails application in production environment (port:80) with Nginx and Unicorn.
## Installation:
Please make sure that your Gemfile in your rails application includes unicorn.
@chebyte
chebyte / setup.md
Created January 9, 2013 22:36 — forked from leesmith/setup.md

Ruby on Rails development setup on Ubuntu 12.04

System update

# change mirror to ubuntu.osuosl.org first
sudo apt-get update

Install common libraries

require 'deathbycaptcha'
require 'watir-webdriver'
@browser = Watir::Browser.new :firefox
@browser.goto "127.0.0.1:8080"
if @browser.alert.exists?
puts @browser.alert.ok
csv.drop(params[:is_column_headings].present? || params[:matched_columns].nil? ? 1 : 0).each_slice(500) do |rows|
ActiveRecord::Base.transaction do # Make sure all record persistance is rolled back if an exception occurs
rows.each do |row|
# load data
columns.values.each_with_index{|named_columns, i| data.merge!(named_columns => row[i]) if named_columns}
# build record
if duplicate_record?(is_skip_duplicates, data, current_user)
row << "This record is potentialy a duplicate and was not #{self.name.split("::")[1].downcase}ed."
status = "errors"
else
irb(main):054:0> a = JSON.parse(open("http://127.0.0.1:3000/api/v1/proxies/list").read)
JSON::ParserError: 757: unexpected token at '"[{\"ip\":\"68.80.135.236\",\"port\":6515,\"updated_at\":\"2012-10-25T22:25:09Z\"},{\"ip\":\"54.247.66.62\",\"port\":8080,\"updated_at\":\"2012-10-25T22:26:21Z\"},{\"ip\":\"184.169.211.220\",\"port\":80,\"updated_at\":\"2012-10-25T22:26:56Z\"},{\"ip\":\"23.22.243.246\",\"port\":8080,\"updated_at\":\"2012-10-25T22:28:03Z\"}]"'
###API CODE###
$:.push(File.dirname(__FILE__) + "../lib")
require "rack/api"
require 'json'
class ProxyResponse
def initialize(app)
@app = app
require "nokogiri"
require "watir-webdriver"
browser = Watir::Browser.new :firefox
browser.goto "http://127.0.0.1:8080/"
browser.javascript_dialog.button('OK').click
if browser.alert.exists?
browser.alert.ok
end
@chebyte
chebyte / tomcat6_init_d_ubuntu
Created August 7, 2012 13:39
tomcat6 init service ubuntu
#!/bin/sh
# Tomcat Startup Script
CATALINA_HOME=/opt/tomcat6; export CATALINA_HOME
JAVA_HOME=/usr; export JAVA_HOME
TOMCAT_OWNER=rails; export TOMCAT_OWNER
start() {
echo -n "Starting Tomcat: "
su $TOMCAT_OWNER -c $CATALINA_HOME/bin/startup.sh
@chebyte
chebyte / rspec_nice_format.rb
Created June 28, 2012 14:28
get nice output format with rspec
for get nice format output from your rspecs you just need create the following file into the root project
.rspec #with the following content
--colour
--format nested