Skip to content

Instantly share code, notes, and snippets.

@erez-rabih
erez-rabih / net_http_patch.rb
Created February 25, 2014 06:28
Net HTTP Patch For Ruby 2.x
require 'net/http'
module HTTPResponseDecodeContentOverride
def initialize(h,c,m)
super(h,c,m)
@decode_content = true
end
def body
res = super
if self['content-length'] && res && res.respond_to?(:bytesize)
self['content-length']= res.bytesize
@erez-rabih
erez-rabih / big_decimal_bug.rb
Created February 26, 2014 08:19
BigDecimal Difference Ruby1.9.3 vs Ruby2.1
#ruby 1.9.3
require 'bigdecimal' ; require 'bigdecimal/util'; (0.5.to_d / 0.99.to_d).to_f # => 0.505050505
#ruby 2.1.0
require 'bigdecimal' ; require 'bigdecimal/util'; (0.5.to_d / 0.99.to_d).to_f # => 0.0
@erez-rabih
erez-rabih / gist:2f9ff8dae5eedb3129dd
Created July 16, 2014 11:31
Logstash Server Configuration
input {
redis {
host => "127.0.0.1"
data_type => "list"
key => "logstash"
# We use the 'json' codec here because we expect to read
# json events from redis.
codec => json
}
log_format ftbpro '$http_host '
'$remote_addr [$time_local] '
'"$request" $status $body_bytes_sent '
'"$http_referer" "$http_user_agent" '
'$request_time '
'$upstream_response_time';
@erez-rabih
erez-rabih / agent.conf
Created July 16, 2014 11:48
Logstash Agent Configuration
input {
file {
path => **YOUR NGINX ACCESS LOG FILE PATH**
type => "web_nginx_access"
}
}
filter {
grok {
type => "web_nginx_access"
@erez-rabih
erez-rabih / nginx-dashboard.json
Last active August 29, 2015 14:06
Nginx Dashboard For Logstash
{
"title": "Nginx Web",
"services": {
"query": {
"list": {
"0": {
"query": "response:[200 TO 299]",
"alias": "OK",
"color": "#7EB26D",
"id": 0,
@erez-rabih
erez-rabih / attr_reader_writer.rb
Last active August 29, 2015 14:10
attr_reader/writer example
class BankAccount
def initialize(balance)
@balance = balance
end
#attr_reader and its equivalent
attr_reader :balance
def balance
@balance
end
#attr_writer and its equivalent
@erez-rabih
erez-rabih / balance_boost.rb
Created December 8, 2014 06:00
When no to use attr_reader and attr_writer in ruby
def temporary_balance_boost
old_balance = balance
balance = balance * 2
puts "Your balance is now #{balance}, you have 10 seconds to use it!"
sleep 10
balance = old_balance
end
def temporary_balance_boost
old_balance = @balance
@erez-rabih
erez-rabih / jenkins-build-pipeline.css
Last active August 29, 2015 14:11
jenkins build pipeline css
#pipelines {display: none;}
#main-panel {width: 100%;}
def temporary_balance_boost
old_balance = self.balance
self.balance = self.balance * 2
puts "Your balance is now #{balance}, you have 10 seconds to use it!"
sleep 10
self.balance = old_balance
end