Skip to content

Instantly share code, notes, and snippets.

View johndel's full-sized avatar
🖖

John Deliyiannis johndel

🖖
View GitHub Profile
@johndel
johndel / myclass.rb
Created May 24, 2013 17:53
Stefanos is losing
class Myclass
def initialize
@attributes = []
end
def method_missing(name, *args)
attribute = name.to_s
if attribute =~ /=$/
@attributes[attribute.chop] = args[0]
else
@johndel
johndel / elements_controller_spec.rb
Created May 31, 2013 09:39
Simple controller spec for testing json response.
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]) }
@johndel
johndel / on_click.cs
Created June 5, 2013 15:56
C# check url response
// 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();
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
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
@johndel
johndel / redis.conf
Created July 9, 2013 14:27
redis config for monit
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"
@johndel
johndel / devise.rb
Created July 20, 2013 18:31
Multiple providers, one solution, generate password randomly.
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
@johndel
johndel / omniauth_callbacks_controller.rb
Created July 20, 2013 18:33
omniauth_controller for multiple providers.
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)
@johndel
johndel / gist:7473591
Last active December 28, 2015 08:39
Fql first attempt: Find TV shows with genre comedy through facebook pages.
require 'koala'
require 'rubygems'
require 'active_record'
ActiveRecord::Base.establish_connection(
:adapter => 'mysql2',
:database => 'test',
:username => 'whatever',
:password => 'whatever',
:host => 'localhost')
@johndel
johndel / complete.rb
Last active December 28, 2015 08:59
FQL test for fun complete.
require 'koala'
require 'pry'
require 'rubygems'
require 'selenium-webdriver'
require 'active_record'
ActiveRecord::Base.establish_connection(
:adapter => 'mysql2',
:database => 'test',
:username => 'whatever',