Skip to content

Instantly share code, notes, and snippets.

James u007

Block or report user

Report or block u007

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View ajigemfile
source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~>4.0.3'
# Use sqlite3 as the database for Active Record
#gem 'sqlite3'
gem 'mysql2'
# Use SCSS for stylesheets
View cphulk management via console.txt
# login as root, and mysql into cphulkd
sudo su
mysql cphulkd
# see blocked / history
select user, INET6_NTOA(address) as address1, service, type, logintime, notes, authservice from login_track where INET6_NTOA(address) like ‘%:-ip here-';
select user, INET6_NTOA(address) as address1, service, type, logintime, notes, authservice from login_track order by logintime desc limit 30;
select user, INET6_NTOA(address) as address1, service, type, logintime, notes, authservice from login_track where type < 0 order by logintime desc limit 30;
@u007
u007 / app : app.rb
Last active Jun 30, 2016
padrino view working!
View app : app.rb
module MyApp
class App < Padrino::Application
use ConnectionPoolManagement
set :login_model, :user_access
register Padrino::Mailer
register Padrino::Helpers
register Padrino::Sprockets
# register Padrino::Cache
# register I18n::JS::Middleware
# register Padrino::Login
@u007
u007 / email_bandwidth.rb
Created Jul 14, 2016
extract email bandwidth usage for a domain grouped by day
View email_bandwidth.rb
cmd = 'grep @domain.com /var/log/maillog | grep retr= | awk {\'print $6" "$1" "$2" "$3" "$11\'} | grep -v retr=0'
output = []
r, io = IO.pipe
fork do
system(cmd, out: io, err: :out)
end
io.close
list = {}
@u007
u007 / config - boot.rb
Last active Jul 24, 2016
fix for padrino with activerecord concern reload issue
View config - boot.rb
Padrino::Reloader.module_eval do
def reload!
list = []
extras = []
rotation do |file|
next unless file_changed?(file)
list << file
end
View reduce params to filtered updates based on active record accept nested attributes with deletion
# ruby
res = params.require(:table).permit(:field1,
table_sub_table_attributes: [:key_field_id, :id, :_destroy])
res[:table_sub_table_attributes] = reduce_params(res[:table_sub_table_attributes], :key_field_id)
# reduce delete to delete existing which is not selected
# and insert only when is not an existing
# does not handle updating existing (which is not used)
def reduce_params(attributes, key_field)
res = []
View pumactl not starting based on
bundle exec pumactl -P /home/project/rails/shared/tmp/pids/puma.pid restart as project@live.sitename.com
DEBUG [50915bef] Command: cd /home/project/rails/releases/20160919165940 && /usr/bin/env RAILS_ENV=production /usr/local/rvm/bin/rvm 2.3.1 do bundle exec pumactl -P /home/project/rails/shared/tmp/pids/puma.pid restart
DEBUG [50915bef] Puma starting in single mode...
DEBUG [50915bef]
DEBUG [50915bef] * Version 3.6.0 (ruby 2.3.1-p112), codename: Sleepy Sunday Serenity
DEBUG [50915bef]
DEBUG [50915bef] * Min threads: 1, max threads: 2
DEBUG [50915bef]
DEBUG [50915bef] * Environment: production
DEBUG [50915bef]
View revel authentication request
func Auth(c *revel.Controller) bool {
if LoggedInCheck() {//write your own
return true
}
email, pass, _ := c.Request.BasicAuth()
//login n password
//TODO check login here
//...
@u007
u007 / README.md
Last active Feb 17, 2017
full git deployment with auto boot of puma for ruby on rails via rvm, with nightly restart of rails
View README.md

SETTING UP

  • 1st, add production origin to git.
  • Next, ssh to remote and do a git init
  • Then on local git:
    • git pull production master
    • git push production master
@u007
u007 / app.go
Last active Mar 10, 2017
buffalo i18n locale
View app.go
// in actions/app.go
/*
directory structure
app/
locales/en-us.yaml
assets/js/locales/
middleware/
actions/tools
*/
import(
You can’t perform that action at this time.