Skip to content

Instantly share code, notes, and snippets.

@deevis
deevis / gist:4513844
Last active December 10, 2015 23:59
add deleted files to be staged for commit
git status | grep deleted | sed 's/.*deleted:\(.*\)/\1/g' | xargs git rm
@deevis
deevis / gist:4521377
Created January 13, 2013 00:41
add activeadmin user sql statement
insert into admin_users (id, email, encrypted_password, created_at, updated_at) values ('1', '[email protected]', '$2a$10$Xsa8cX1G4jK9EGFV17UkOeTQnMPlp6GNaRld8pnVlIELUWTLY0Xx6', now(), now());
@deevis
deevis / gist:4521473
Created January 13, 2013 00:57
Deploy a jar to a maven 2 repository
mvn deploy:deploy-file -Dfile=./hibernate-validator-3.1.0.GA-sources.jar -DgroupId=org.hibernate -DartifactId=hibernate-validator -Dversion=3.1.0.GA -Dpackaging=jar -DgeneratePom=true -Durl=sftp://soa.dev.hq.icentris:22/home/soa/tomcat/webapps/ROOT/repository2 -DrepositoryId=local2
@deevis
deevis / gist:4527120
Created January 14, 2013 01:16
ActiveRecord - group by with count and having
To perform this SQL statement:
-----------------------------------------------------------------------------------
select term_id, info_type_id, count(*) from item_feedbacks ifb, items i
21where ifb.item_id = i.id and i.source = 'Imgur'
group by term_id, info_type_id having count(*) > 15 order by count(*) desc ;
Here's the RoR ActiveRecord equivalent:
-----------------------------------------------------------------------------------
l=ItemFeedback.select("term_id, info_type_id, count(*) as count")
@deevis
deevis / gist:6002077
Last active December 19, 2015 18:58
Print out all Gems and their descriptions
require 'prawn'
Prawn::Document.generate("gems.pdf") do
`bundle list`.split("\n")[1..-1].map{|s| s.gsub(" * ","")}.each do |g|
puts g
text "\n\n<b>#{g}</b>", inline_format: true
text "---------------------------"
s = `gem specification #{g.split.first}` rescue ""
description = s.scan( /.*\ndescription: (.*)\nemail.*/m ).last.first rescue nil
if !description || description.empty?
@deevis
deevis / gist:6031108
Created July 18, 2013 17:15
Get source location of all defined methods (or instance_methods) for a given Class
#Get source location of all defined methods (or instance_methods) for a given Class
klazz=String
type=:instance_method # type=:method
klazz.send(type.to_s.pluralize.to_sym,false).sort.map{|m| [m,klazz.send(type,m).source_location]}.select{|x| x[1]}
@deevis
deevis / Ruby - Subclassers and methods
Created August 26, 2013 21:33
Ruby - Build map of class and all subclasses as keys and with each key's locally declared instance_methods as the values
def my_methods_and_recurse(klazz,results={})
results[klazz.name] = klazz.instance_methods(false)
klazz.subclasses.each do |sc|
my_methods_and_recurse(sc, results)
end
results
end
@deevis
deevis / Rails - load controllers and models
Last active December 21, 2015 18:19
Reload Rails Controllers and/or Models
# Controllers
Dir["#{Rails.root}/../pyr/*/app/controllers/**/*.rb"].each{|p| puts "require #{p}";require p};nil
# Models
Dir["#{Rails.root}/../pyr/*/app/models/**/*.rb"].each{|p| puts "require #{p}";require p};nil
pyr_models = ActiveRecord::Base.subclasses.map(&:name).select{|c| c =~ /Pyr.*/}.sort
pyr_polys = {}.tap{|m| pyr_models.each{|klazz| m[klazz] = begin;obj=klazz.constantize.send(:first); app.polymorphic_path(obj) if obj;rescue Exception => e; e.message;end};nil}
pyr_models_mapped = pyr_polys.select{|k,v| v =~ /\/.*/}.keys
# Those without polymorphic paths
(pyr_models - pyr_models_mapped).sort.each {|m| puts m}
# Those with polymorphic paths
@deevis
deevis / gist:ef5071d6d251acae765f
Created November 18, 2014 06:41
Nginx, Faye, Nodejs and SSL configuration
NGINX - Configured to forward root domain requests to SSL, subdomains w/o SSL, and to upgrade /faye to websocket
--------------------------------------------------------------------------------------------------------------------
upstream my_app_upstream {
server unix:///var/run/my_app/my_app.sock;
}
server {
listen 80;
server_name mydomain.com;