This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Myclass | |
def initialize | |
@attributes = [] | |
end | |
def method_missing(name, *args) | |
attribute = name.to_s | |
if attribute =~ /=$/ | |
@attributes[attribute.chop] = args[0] | |
else |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'spec_helper' | |
describe Api::ElementsController do | |
let!(:user) { FactoryGirl.create(:user) } | |
let(:fire) { FactoryGirl.create(:element, name: "fire") } | |
let(:uber_fire) { FactoryGirl.create(:element, name: "uber fire") } | |
let(:vesuvius) { FactoryGirl.create(:element, name: "vesuvius", parents: [fire, uber_fire, fire]) } | |
let(:kolumbo) { FactoryGirl.create(:element, name: "kolumbo", parents: [fire, uber_fire, fire]) } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Response | |
try | |
{ | |
using (var response = (HttpWebResponse)httpWReq.GetResponse() as HttpWebResponse) | |
{ | |
if (httpWReq.HaveResponse && response != null) | |
{ | |
using (var reader = new StreamReader(response.GetResponseStream())) { | |
string result = reader.ReadToEnd(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
check process redis-server | |
with pidfile "/var/run/redis.pid" | |
start program = "/etc/init.d/redis-server start" | |
stop program = "/etc/init.d/redis-server stop" | |
if 2 restarts within 3 cycles then timeout | |
if totalmem > 100 Mb then alert | |
if children > 255 for 5 cycles then stop | |
if cpu usage > 95% for 3 cycles then restart | |
if failed host 127.0.0.1 port 6379 then restart | |
if 5 restarts within 5 cycles then timeout |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
set daemon 30 # check services at 2-minute intervals | |
set logfile /var/log/monit.log | |
set idfile /var/lib/monit/id | |
set statefile /var/lib/monit/state | |
set eventqueue | |
basedir /var/lib/monit/events # set the base directory where events will be stored | |
slots 100 # optionally limit the queue siz | |
set httpd port 2812 | |
allow 0.0.0.0/0.0.0.0 | |
allow username:password |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
check process redis-server | |
with pidfile "/var/run/redis/redis.pid" | |
start program = "/etc/init.d/redis-server start" | |
stop program = "/etc/init.d/redis-server stop" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def self.from_omniauth(auth) | |
unless provider = Provider.where(auth.slice(:provider, :uid)).first # New User | |
provider = Provider.new(provider: auth.provider, uid: auth.uid, oauth_token: auth.credentials.token) | |
user = User.where(email: auth.info.email).first # If user is already a devise user | |
if user.nil? # New user | |
random_password = (0...8).map{(65+rand(26)).chr}.join | |
user = User.create(email: auth.info.email, password: random_password, password_confirmation: random_password, confirmed_at: Time.now) | |
end | |
provider.user = user | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class OmniauthCallbacksController < Devise::OmniauthCallbacksController | |
def all | |
#raise request.env["omniauth.auth"].to_yaml | |
omniauth = request.env["omniauth.auth"] | |
provider = User.from_omniauth(omniauth) | |
if provider.persisted? | |
flash.notice = "Successful login" | |
sign_in(provider.user) | |
@after_sign_in_url = after_sign_in_path_for(provider.user) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'koala' | |
require 'rubygems' | |
require 'active_record' | |
ActiveRecord::Base.establish_connection( | |
:adapter => 'mysql2', | |
:database => 'test', | |
:username => 'whatever', | |
:password => 'whatever', | |
:host => 'localhost') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'koala' | |
require 'pry' | |
require 'rubygems' | |
require 'selenium-webdriver' | |
require 'active_record' | |
ActiveRecord::Base.establish_connection( | |
:adapter => 'mysql2', | |
:database => 'test', | |
:username => 'whatever', |