Skip to content

Instantly share code, notes, and snippets.

View reu's full-sized avatar

Rodrigo Navarro reu

View GitHub Profile
@reu
reu / proxy-non-blocking.rs
Last active December 16, 2023 13:44
Simple TCP proxy using thread per connection and non blocking IO
use std::{
io::{self, Read, Write},
net::{TcpListener, TcpStream},
os::fd::{AsRawFd, RawFd},
thread,
};
const READ: libc::c_short = libc::POLLRDNORM;
const WRITE: libc::c_short = libc::POLLWRNORM;
@reu
reu / deploy.rb
Created November 6, 2010 12:41
Capistrano deploy recipe for database configuration
# Bundler Integration
require "bundler/capistrano"
# Application Settings
set :application, "yourapplicationname"
set :user, "serveruser"
set :deploy_to, "/home/#{user}/rails-applications/#{application}"
set :rails_env, "production"
set :use_sudo, false
set :keep_releases, 3
@reu
reu / tmux.conf
Created September 10, 2023 18:03
set -g default-terminal "screen-256color"
set -g terminal-overrides 'xterm*:smcup@:rmcup@'
set-option -sa terminal-overrides ",xterm*:Tc"
set -s escape-time 10
setw -g xterm-keys on
set -g mouse on
setw -g mode-keys vi
unbind -n -Tcopy-mode-vi MouseDragEnd1Pane
set -g base-index 1
@reu
reu / expression.ts
Last active August 21, 2023 15:21
Expression parser using combinators
import {
any,
char,
delimited,
int,
many0,
map,
multispace0,
nat,
parse,
@reu
reu / sig.rb
Created July 12, 2023 17:24
Ruby reactive signal implementation
require "set"
class Sig
def initialize(&computation)
@observers = Set.new
@dependencies = Set.new
@computation = computation || proc { nil }
compute if block_given?
end
@reu
reu / date.rs
Last active March 15, 2023 14:02
Operator overloading for building dates in Rust (don't, just don´t)
use std::ops::{Div, Sub};
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
pub enum Month {
Jan = 1,
Feb = 2,
Mar = 3,
Apr = 4,
Mai = 5,
Jun = 6,
@reu
reu / pub-sub.js
Created April 9, 2013 01:51
node.js redis pub-sub example
var redis = require("redis")
, subscriber = redis.createClient()
, publisher = redis.createClient();
subscriber.on("message", function(channel, message) {
console.log("Message '" + message + "' on channel '" + channel + "' arrived!")
});
subscriber.subscribe("test");
@reu
reu / line-reader.js
Created January 4, 2014 16:38
How to read a file line by line in Node.js using the yet unstable Readline library (http://nodejs.org/api/readline.html)
var fs = require("fs"),
readline = require("readline");
var reader = readline.createInterface({
input: fs.createReadStream("large-file.txt"),
output: fs.createWriteStream("/dev/null"),
terminal: false
});
reader.on("line", function(line) {
@reu
reu / example.js
Last active January 4, 2023 00:34
HTML builder DSL
import { h1, div, p } from "./html";
div([
h1({ class: "title" }, "Title"),
p("A nice text"),
]);
@reu
reu / anymap.rs
Created April 12, 2022 22:15
Rust AnyMap
use std::any::{Any, TypeId};
use std::collections::HashMap;
#[derive(Default)]
pub struct AnyMap {
map: HashMap<TypeId, Box<dyn Any>>,
}
impl AnyMap {
pub fn insert<T: 'static>(&mut self, t: T) {