Skip to content

Instantly share code, notes, and snippets.

@foxumon
foxumon / check_for_errors.sh
Created March 3, 2017 20:59
Delete PHP files with errors
find ... -iname "*.php" -exec php -l {} \; | grep -i "Errors.parsing"
@foxumon
foxumon / check_string.rb
Created March 3, 2017 20:55
Global replace in RoR console
a = MODEL.where("COLUMN like ?", "%SEARCH%");0
puts a.length
puts " "
a.all.each do |a|
puts a.id
end;0
@foxumon
foxumon / csv_export.rb
Created March 3, 2017 20:53
Export table to CSV with select attributes in rails console
date = Date.new(2016,12,15)
l = Table.where("created_at > ? AND column != 'variable'", date)
ActiveRecord::Base.logger = nil
results = []
l.each do |i|
u = User.where(:email => i.email)
if u.present?
if Table.where(:email => u[0].email).blank?
results << {:email=>i.email,:member=>'y'}
@foxumon
foxumon / nginx.conf
Created March 3, 2017 20:52
Nginx redirect load balancing
http {
split_clients "${remote_addr}" $mirror {
33% "http://google.com";
33% "http://yahoo.com";
* "http://bing.com";
}
server {
listen 0.0.0.0:80;
@foxumon
foxumon / csv_export.rb
Created April 29, 2016 20:19
Export table to CSV with all attributes in rails console
require 'csv'
file = "#{Rails.root}/public/data.csv"
table = User.all;0 # ";0" stops output. Change "User" to any model.
CSV.open( file, 'w' ) do |writer|
writer << table.first.attributes.map { |a,v| a }
table.each do |s|
writer << s.attributes.map { |a,v| v }