Skip to content

Instantly share code, notes, and snippets.

View johndel's full-sized avatar
🖖

John Deliyiannis johndel

🖖
View GitHub Profile
@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"
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
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
@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();
@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 / 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 / test.rb
Created April 4, 2013 10:38
It returns Favorite Game: ["Mario", "Contra", "Metroid"] instead of looping through array. Guess why :)
def describe_favorites(*games)
games.each do |game|
puts "Favorite Game: #{game}"
end
end
describe_favorites(['Mario', 'Contra', 'Metroid'])
@johndel
johndel / gsadmin-initializer.rb
Created April 2, 2013 23:55
Generator for initializing gsadmin setup
module Gsadmin
module Generators
class InitializerGenerator < Rails::Generators::Base
source_root File.expand_path("../templates", __FILE__)
desc "Gsadmin installation generator."
def welcome
say "Thank you for using gsadmin, if you have any questions, my email is [email protected]", :cyan
end
@johndel
johndel / baby
Created March 24, 2013 13:59
Test tank bot for RTanque. Still baby steps :)
class Baby < RTanque::Bot::Brain
NAME = 'baby'
include RTanque::Bot::BrainHelper
def tick!
test_sensors
if sensors.position.on_left_wall?
command.speed = 3
command.heading = Math::PI
command.radar_heading = Math::PI
@johndel
johndel / gsadmin.rb
Created March 21, 2013 18:03
initializers/gsadmin.rb
Gsadmin.config do |config|
config.route = "admin"
config.devise_model = "admin"
end