Skip to content

Instantly share code, notes, and snippets.

@opensourcegeek
opensourcegeek / sample.rs
Created February 21, 2018 22:48
Lifetime issue with bufwriter
extern crate ssh2;
use std::net::TcpStream;
use std::path::Path;
use std::io::BufWriter;
use ssh2::Session;
use ssh2::{OpenType, WRITE, TRUNCATE};
@opensourcegeek
opensourcegeek / ssh2-sample.rs
Created February 21, 2018 22:21
Failing code
extern crate ssh2;
use std::net::TcpStream;
use ssh2::Session;
fn create_session() -> Session {
let tcp = TcpStream::connect("test:22").expect("Cannot connect");
let mut sess = Session::new().expect("cannot start session");
sess.handshake(&tcp).expect("handshake failed");
use std::io::Read;
use std::time::Instant;
use std::io::Result;
use std::io::{Error, ErrorKind};
use std::cmp;
pub struct UploadData {
pub total_data_size: u64,
pub timeout_in_sec: u64,
pub start_time: Instant,
@opensourcegeek
opensourcegeek / server.rs
Created November 14, 2016 19:43
Rust code to look for bacons and sausages
#[macro_use]
extern crate nickel;
extern crate rustc_serialize;
extern crate scan_dir;
extern crate csv;
use std::ops::Deref;
use std::collections::BTreeMap;
use std::collections::HashMap;
use std::{thread, time};
@opensourcegeek
opensourcegeek / server.py
Created November 14, 2016 19:41
Python code to look for bacons and sausages
import os
import thread
from Queue import Queue
from collections import deque
import time
from bottle import route, run, template
from daemonizer import Daemonizer
MAX_Q_LENGTH = 60 # rolling avg for a minute
@opensourcegeek
opensourcegeek / simple.cc
Last active August 29, 2015 14:24
Slight modification of https://github.com/nikhilm/uvbook/blob/master/code/progress/main.c which uses uv_thread_create with nan
#include <nan.h>
#include <random>
#include <uv.h>
uv_loop_t *loop;
uv_async_t async;
using namespace v8;
@opensourcegeek
opensourcegeek / extend.sh
Last active August 29, 2015 14:21 — forked from wvengen/extend.sh
#!/bin/sh
# extend non-HiDPI external display on DP* above HiDPI internal display eDP*
# see also https://wiki.archlinux.org/index.php/HiDPI
# you may run into https://bugs.freedesktop.org/show_bug.cgi?id=39949
# https://bugs.launchpad.net/ubuntu/+source/xorg-server/+bug/883319
EXT=`xrandr --current | sed 's/^\(.*\) connected.*$/\1/p;d' | grep -v ^eDP | head -n 1`
INT=`xrandr --current | sed 's/^\(.*\) connected.*$/\1/p;d' | grep -v ^DP | head -n 1`
ext_w=`xrandr | sed 's/^'"${EXT}"' [^0-9]* \([0-9]\+\)x.*$/\1/p;d'`
@opensourcegeek
opensourcegeek / category_theory.js
Last active August 29, 2015 14:00
Category theory as explained by Mike Stay (http://jscategory.wordpress.com/source-code/)
// This is work by Mike Stay, (http://jscategory.wordpress.com/source-code/)
// I place all this code in the public domain.
// Library of contracts and functors.
var CT = (function (){
var call = Function.prototype.call;
var slice = call.bind([].slice);
var getClassName = call.bind({}.toString);
@opensourcegeek
opensourcegeek / connection_pool
Created March 28, 2014 00:13
A quick and easy way to reconnect to mysql when connection is lost, it uses gevent queues but still the idea should work whichever way the connections are pooled.
from gevent import monkey
monkey.patch_socket()
import logging
import gevent
from gevent.queue import Queue
import pymysql as db
logging.basicConfig(level=logging.DEBUG)
LOGGER = logging.getLogger("connection_pool")
#!/bin/bash
#script extraido de: http://paulocassiano.wordpress.com/2008/08/29/deixando-o-gedit-com-a-cara-do-textmate/
#tip for better "resolution" here: http://blog.siverti.com.br/2008/05/22/fonte-monaco-no-ubuntugedit/
cd /usr/share/fonts/truetype/
#TODO: put validation if folder already exists
sudo mkdir ttf-monaco