Skip to content

Instantly share code, notes, and snippets.

View universal's full-sized avatar

Johannes / universa1 universal

View GitHub Profile
@universal
universal / backup.yaml
Created June 21, 2013 10:04
recursive directory creation, only last directory has owner and group set
---
- hosts: some_host
user: some_user
sudo: yes
tasks:
- name: ensure backup gem is installed
gem: name=backup state=present
- name: ensure Backup dir is present
file: state=directory path=/home/git/Backup/models owner=git group=git recurse=yes
@universal
universal / matches_controller_spec.rb
Created July 16, 2013 09:43
cancan and authentication check
describe MatchesController do
let(:group) {FactoryGirl.create(:group)}
context "requires login and checks authorization" do
it "for GET 'new'" do
controller.should_receive(:authenticate_user!).and_return(false)
expect{get :new, group_id: group.id}.to raise_error(CanCan::AccessDenied)
end
it "for POST 'create'" do
<!DOCTYPE html>
<html>
<body>
<video autobuffer="autobuffer" class="video_thumbnail" controls="controls" poster="/assets/rails.png" src="movie.mp4">
</video>
</body>
</html>
c = "abc"; {a: "b", c: case c
when "abc"
"cba"
when "cba"
"abc"
end
}
=> {:a=>"b", :c=>"cba"}
## either this
response.each do |chunk|
[[/[\r\n]+/, ''], [/>\s+</, '><']].each do |reg, rep|
chunk.gsub! reg, rep
end
end
# or that
response = response.map do |chunk|
chunk.gsub(/[\r\n]+/, '').gsub(/>\s+/, '>').gsub(/>\s+</, '><').gsub(/; \s+/, '; ').gsub(/{ \s+/, '{ ').gsub(/<!--(.|\s)*?-->/, '')
@universal
universal / member.rb
Last active December 23, 2015 23:39 — forked from anonymous/gist:6711528
formatting and mutliple files...
class Member < ActiveRecord::Base
belongs_to :project
belongs_to :users
attr_accessible :project_id, :user_id
end
@universal
universal / member.rb
Last active December 23, 2015 23:49 — forked from anonymous/member.rb
class Member < ActiveRecord::Base
belongs_to :project
belongs_to :users
attr_accessible :project_id, :user_id
end
upstream some.where {
server unix:/home/somewhere/deploy/somewhere/tmp/puma.sock;
}
server {
listen 80;
server_name some.where www.some.where;
location / {
@universal
universal / bluepill.rb
Last active February 27, 2019 03:56
sample bluepill file with puma and sidekiq
Bluepill.application("gitlabhq", :foreground => false, :log_file => "/home/deploy/deploy/gitlabhq/shared/log/bluepill.log", :base_dir => "/home/deploy/.bluepill") do |app|
app.uid = "deploy"
app.gid = "deploy"
app.working_dir = "/home/deploy/deploy/gitlabhq/current"
app.process("web-1") do |process|
process.start_command = "puma -b unix:///home/deploy/deploy/gitlabhq/shared/puma.sock"
process.daemonize = true
class Manufacturer < ActiveRecord::Base
def self.selectable
result = []
result << self.joins(:cars).joins(cars: :basic_articles).where(published: true, cars:{published: true}, basic_articles: {published: true, requires_extra: false}).map{ |r| r.id }
result << self.joins(:cars).joins(cars: :basic_articles).joins(cars: [basic_articles: :extras]).where(published: true, cars:{published: true}, basic_articles: {published: true, requires_extra: true}).map{ |r| r.id }
return self.where(id: result)
end
end