Skip to content

Instantly share code, notes, and snippets.

@dasibre
dasibre / gist:8959376
Created February 12, 2014 16:43
Network I/O ruby Event handling chat server
#event loop demystified ruby
#Working with network I/O in Ruby is so easy:
#https://practicingruby.com/articles/event-loops-demystified
require 'socket'
# Start a server on port 9234
server = TCPServer.new('0.0.0.0', 9234)
# Wait for incoming connections
while io = server.accept
@dasibre
dasibre / gist:8959399
Last active August 29, 2015 13:56
Ruby I/O
class IOLoop
# List of streams that this IO loop will handle.
attr_reader :streams
def initialize
@streams = []
end
# Low-level API for adding a stream.
def <<(stream)
class Manuscript
include Mongoid::Document
embeds_many :authors
field :code, type: String
field :title, type: String
field :status, type: String
field :status_date, type: Date
end
@dasibre
dasibre / rsyslog.conf
Created March 5, 2014 17:15
Rsyslog Configuration sample file
######################
MODULES
######################
$ModLoad imuxsock
$ModLoad imklog
######################
Directives
######################
def change(str)
alphabet_count = str.downcase.scan(/[a-z]/).count
if alphabet_count > 0
ones = "1"*alphabet_count
zeroes = 26
ones_zeroes = ones.ljust(zeroes-alphabet_count,'0')
else
"0"*26
end
end
<source>
type embedded_elasticsearch
</source>
<source>
type kibana_server
bind 0.0.0.0
port 24300
mount /kibana/
access_log_path var/log/kibana/access.log
#! /bin/sh
### BEGIN INIT INFO
# Provides: logstash
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start daemon at boot time
# Description: Enable service provided by daemon.
### END INIT INFO
@dasibre
dasibre / Vagrantfile
Created July 25, 2014 17:24
Default Vagrantfile
# -*- mode: ruby -*-
# vi: set ft=ruby :
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"
Vagrant.require_version ">= 1.5.0"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
# All Vagrant configuration is done here. The most common configuration
@dasibre
dasibre / testsuite
Last active August 29, 2015 14:13
javascript custom test suite
<script type="text/javascript">
(function foo() {
this.buzz = function buzz() {
return 'buzz';
}
console.log('I am a self invoking function');
})();
(function() {
@dasibre
dasibre / Bin To Dec
Created January 28, 2015 14:20
Binary to Decimal
def bin_to_dec(str_binary)
base = 2
results = 0
size = str_binary.size
exponent = size - 1
0.upto(exponent) do |index|
results += (str_binary[index].to_i * base ** exponent)
exponent -= 1
end
results