Skip to content

Instantly share code, notes, and snippets.

@inre
inre / gist:254d6afcd8754e774dc7
Created August 29, 2014 19:56
Try reflections in swift
class Document {
func properties() -> [String] {
var array: [String] = []
var mirror = reflect(self)
for i in 0..<mirror.count {
if mirror[i].0 != "super" {
array.append(mirror[i].0)
}
}
return array
@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)!
}
#!/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
import Foundation
@objc class Timer: NSObject {
var timer: NSTimer?
var handler: (() -> ())!
let duration: Double
init(duration: Double) {
self.duration = duration
super.init()
@inre
inre / blink.rs
Created August 3, 2015 21:48
gpio-pi: Blink example
@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 / 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 {
def generate_token(length=8)
alphanumerics = ('a'..'z').to_a.concat(('A'..'Z').to_a.concat(('0'..'9').to_a))
self.token = alphanumerics.sort_by{rand}.to_s[0..length]
# Ensure uniqueness of the token..
generate_token unless Widget.find_by_token(self.token).nil?
end
# populate test database before running tests
Rake::Task["db:test:prepare"].enhance do
Customer.establish_connection "test"
Domain.establish_connection "test"
PopulationHelper.populate
end
@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>,
}