Skip to content

Instantly share code, notes, and snippets.

View kany's full-sized avatar

Frank Kany kany

  • Rickman, TN
View GitHub Profile
@kany
kany / sudo_crontab_e
Last active August 29, 2015 13:56
Cronjob to reboot server 1 minute past every hour
# To Edit Root Cron Jobs
#sudo crontab -e
# Reboot 1 minute past every hour, log errors if any generate
01 * * * * /sbin/reboot > /home/calvin2/miner_cron_job_log.txt 2>&1
# Reboot every 30 minutes, log errors if any generate
*/30 * * * * /sbin/reboot > /home/calvin2/miner_cron_job_log.txt 2>&1
@kany
kany / active_record_outside_of_rails.rb
Created March 27, 2014 15:11
Using ActiveRecord outside of a Rails app
require 'active_record'
require 'mysql2'
# Database Connection
ActiveRecord::Base.establish_connection(
adapter: 'mysql2', # or 'postgresql' or 'sqlite3'
host: 'localhost',
database: 'chc_user_auth_direct_login',
username: 'root',
password: ''
@kany
kany / cropper.rb
Created September 24, 2014 01:59
Cropping images with paperclip
# lib/paperclip_processors/cropper.rb
module Paperclip
class Cropper < Thumbnail
def transformation_command
if crop_command
puts "CROP: #{crop_command + super.join(' ').sub(/ -crop \S+/, '').split(' ')}"
crop_command + super.join(' ').sub(/ -crop \S+/, '').split(' ')
else
super
end
@kany
kany / rubocop.sh
Created January 14, 2015 18:40
rubocop - script to install rubocop and rubocop-rspec gems before running rubocop
# -------
# rubocop
# -------
# example usage:
# check a directory: rubocop app/controllers
# check a file: rubocop app/controllers/application_controller.rb
# check rspec directory: rubycop spec/controllers
# check rspec file: rubycop spec/controllers/application_controller_spec.rb
run_rubocop(){
if gem list | gem list | grep 'rubocop\|rubocop-rspec' ; then
@kany
kany / libv8.rb
Created April 23, 2015 21:24
libv8 issues
http://stackoverflow.com/questions/24081473/how-to-install-therubyracer-gem-on-10-10-yosemite
gem uninstall libv8
brew install v8
gem install therubyracer
gem install libv8 -v '3.16.14.3' -- --with-system-v8
@kany
kany / iZoom.min.js
Created August 5, 2012 04:23
Image - Magnifying Glass - jQuery
consignment_items_controller.rb
def show
@consignment_item = ConsignmentItem.find(params[:id])
@magnified_images = ""
@consignment_item.images.each_with_index do |image, index|
@magnified_images += "jQuery('#magnifyimage_#{index}').iZoom();"
end
end
@kany
kany / gist:3640501
Created September 5, 2012 17:25
Importing Large MySQL Databases - Mac OS
1) Install Keka
http://www.kekaosx.com/en/
2) (optional) split your import file(http://www.webmaster-source.com/2011/09/26/how-to-import-a-very-large-sql-dump-with-phpmyadmin/)
3) Compress your sql dump file(s) into a 7z file using Keka.
4) From the terminal, run:
7z x -so backup_some_app_data.sql.7z | mysql -u root some_app_db
@kany
kany / gist:3658110
Created September 6, 2012 16:22
WTF MySQL! Eating up diskspace
How to clear all those 'mysql-bin.00000**' files from /usr/local/var/mysql:
1) mysql -u root
2) flush logs;
3) reset master;
DONE!
@kany
kany / unpack a gem
Created September 16, 2012 01:50
Unpacking a gem to a specific directory
Rhodes application stack needs required gem unpacked to the lib directory.
frankkany:rhodesprojects $ gem unpack mechanize --target ~/Desktop
Unpacked gem: '/Users/frankkany/Desktop/mechanize-2.5.1'
@kany
kany / ubuntu,rvm,crontab
Created November 5, 2012 01:24
ubuntu,rvm,crontab
http://www.wyliethomas.com/blog/2011/08/24/rvm-rake-and-cron-on-ubuntu/
RVM, Rake and Cron on Ubuntu
by admin on August 24th, 2011
Tennnngh! I read countless blog posts, tried numerous approaches that I found and rebuilt the server more than a couple times. And finally I found what the missing piece was for getting a rake command to run in cron with rvm.
Most of the results I found (on stackoverflow) flagged the solution as adding the path to your rvm in your line item in crontab. Something like /home/username/.rvm/gems/rake my_awesome_task… etc. I tried every variation of that I could think of and got the same results.
I dont use cron every day so this was a revelation to me. I found out that you can set variables, environment variables in your crontab file.