Skip to content

Instantly share code, notes, and snippets.

const levelup = require('levelup')
const leveldown = require('leveldown')
const config = require('../config')('persistent')
const path = require('path')
const lodash = require('lodash')
const { promisify } = require('util')
const { decode, encode } = require('./de')
const openDatabase = (file, options) =>
promisify(levelup)(leveldown(file, options))
use std::fmt::Debug;
use std::any::Any;
use std::io;
// Logger function for any type that implements Debug.
fn log<T: Any + Debug>(value: &T) {
let value_any = value as &Any;
// try to convert our value to a String. If successful, we want to
// output the String's length as well as its value. If not, it's a
@inre
inre / fragments.rs
Last active September 23, 2015 20:50
Fragments
pub trait Index {
fn from_usize(i: usize) -> Self;
fn as_usize(&self) -> usize;
}
#[derive(Debug)]
pub struct Fragments<E, I: Index> {
list: Vec<Option<E>>,
free: Vec<I>,
}
@inre
inre / logic.rs
Last active August 29, 2015 14:27
Digital logic
use std::io;
#[derive(Debug, Copy, Clone)]
pub enum Logic {
High,
Low
}
#[derive(Debug, Copy, Clone)]
pub enum Logic3 {
@inre
inre / fs.rs
Created August 10, 2015 08:42
MIO File
#[derive(Debug)]
pub struct Selector {
sys: File
}
impl FromRawFd for Selector {
unsafe fn from_raw_fd(fd: RawFd) -> Selector {
Selector { sys: File::from_raw_fd(fd) }
}
}
@inre
inre / blink.rs
Created August 3, 2015 21:48
gpio-pi: Blink example
@inre
inre / gpio.rs
Created July 31, 2015 20:18
Blink led on raspberry pi 9 (Rust lang)
#![feature(core_intrinsics)]
#[warn(dead_code)]
//#[warn(unused_assignments)]
extern crate mmap;
extern crate libc;
use libc::*;
use std::ffi::CString;
use std::path::Path;
use mmap::{MemoryMap,MapOption};
import Foundation
@objc class Timer: NSObject {
var timer: NSTimer?
var handler: (() -> ())!
let duration: Double
init(duration: Double) {
self.duration = duration
super.init()
#!/bin/bash
# -----------------------------------------------------------------------
# Installs Ruby 2.2 using rbenv/ruby-build on the Raspberry Pi (Raspbian)
#
# Run from the web:
# bash <(curl -s raw_script_url_here)
# -----------------------------------------------------------------------
# Set up variables
@inre
inre / gist:7c93405e43e75f4dae0e
Created November 4, 2014 21:48
Replace with regular expression
import Foundation
struct Regex {
let pattern: String
let options: NSRegularExpressionOptions!
private var matcher: NSRegularExpression {
return NSRegularExpression(pattern: self.pattern, options: self.options, error: nil)!
}