Skip to content

Instantly share code, notes, and snippets.

View zimbatm's full-sized avatar
🦙
nixified

Jonas Chevalier zimbatm

🦙
nixified
View GitHub Profile
use std::path::Path;
static PATHS: [&'static str, .. 4] = ["/bin", "/sbin", "/usr/bin", "/usr/sbin"];
// Tries to find an executable
// TODO: Look for the executable bit for the select user/group
fn look_path(program: ~str, root: ~Path) -> Option<Path> {
let cmd = Path::new(program.clone());
if cmd.is_absolute() || program.contains("/") { // TODO: Use path::SEP
Some(cmd)
@zimbatm
zimbatm / with_args.rb
Created May 13, 2014 12:37
Useful little ruby extension
class Proc
def with_args(*args, &block)
proc do |obj|
call(obj, *args, &block)
end
end
end
class Symbol
@zimbatm
zimbatm / bm.rb
Created May 16, 2014 22:10
Time benchmark
# gem install benchmark-ips
require 'benchmark/ips'
class << Time
attr_accessor :current
end
Time.current = Time.now
Benchmark.ips do |x|
x.report("Time.now") do |n|
@zimbatm
zimbatm / netlink_test.c
Last active August 29, 2015 14:01
Used to detect if the netlink linux interface works properly
@zimbatm
zimbatm / default.nix
Created June 29, 2014 18:54
root nix for direnv
{ pkgs ? (import <nixpkgs> {})
, stdenv ? pkgs.stdenv
, go ? pkgs.go
, git ? pkgs.git
}:
let
gitref = { name, source }:
import (
pkgs.runCommand "${name}-gitref"
{ pkgs ? (import <nixpkgs> {})
, stdenv ? pkgs.stdenv
, go ? pkgs.go
, git ? pkgs.git
}:
rec {
readChop = with builtins; path:
let
str = readFile path;
@zimbatm
zimbatm / docker-socket
Last active August 29, 2015 14:06
Forward /var/run/docker.sock to boot2docker
#!/bin/sh
#
# Instead of having to set DOCKER_HOST or run `$(boot2docker shellinit)` just start this
# script in the background.
#
# Depends on `brew install boot2docker socat`
socket=`boot2docker socket 2>/dev/null | sed 's|tcp://||'`
exec sudo socat -d -d -ls UNIX-LISTEN:/var/run/docker.sock,fork,mode=0777 TCP4:$socket
@zimbatm
zimbatm / rmlint.rb
Created October 13, 2014 11:06
Homebrew formula for rmlint
require "formula"
class Rmlint < Formula
homepage "https://github.com/sahib/rmlint"
head "https://github.com/zimbatm/rmlint.git", branch: "master"
def install
system "make", "install", "PREFIX=#{prefix}"
end
end
@zimbatm
zimbatm / config_dsl.rb
Last active August 29, 2015 14:08
Small generic DSL for the configuration pattern in ruby
# Encapsulate the configuration DSL pattern.
#
# Any `X=(value)` setter method on the given +obj+ is translated into `X(value)` method
# in the context of this object.
class ConfigDSL < BasicObject
def initialize(obj, &config)
@self = obj
call(&config)
end
""" Settings
"" Global
set nocompatible
set encoding=utf-8
"" Plugged
call plug#begin('~/.vim/plugged')
Plug 'tpope/vim-sensible'