Skip to content

Instantly share code, notes, and snippets.

View carloe's full-sized avatar

Carlo Eugster carloe

View GitHub Profile
extension Date {
var quarter: Int {
let month = Calendar.current.dateComponents([.month], from: self).month!
return month / 3 + 1
}
var beginningOfQuarter: Date {
var calendar = Calendar.current
calendar.timeZone = .current
let inComps = calendar.dateComponents([.year, .month], from: self)
@carloe
carloe / Realm+RxSwift.swift
Created October 20, 2016 21:18
Observe Realm changes with RxSwift
//
// Realm+RxSwift.swift
//
// Created by Carlo Eugster on 18/06/16.
// Copyright © 2016 relaunch. All rights reserved.
//
import Foundation
import RealmSwift
import RxSwift
#import <Foundation/Foundation.h>
@interface Measure : NSObject
+ (NSTimeInterval)timing:(void (^)())blockName;
@end
@implementation Measure
@carloe
carloe / pixelsort.pde
Created October 2, 2014 08:04
Scaffolding for a processing pixel sorter
import java.util.Collections;
Sorter sorter;
PImage photo;
void setup() {
photo = loadImage("Foto3.JPG");
sorter = new Sorter();
sorter.init(photo);
photo = sorter.image();
@carloe
carloe / proof.md
Last active August 29, 2015 13:59
keybase proof

Keybase proof

I hereby claim:

  • I am carloe on github.
  • I am carlo (https://keybase.io/carlo) on keybase.
  • I have a public key whose fingerprint is 4CD1 AE20 8F38 6560 364E 40E8 3A54 7D52 3BB6 CE9D

To claim this, I am signing this object:

@carloe
carloe / electoral_votes.py
Created November 7, 2012 02:55
Grabs the current electoral vote counts from huffingtonpost.com
#!/usr/bin/env python
# encoding: utf-8
import re
from urllib import urlopen
html = urlopen("http://elections.huffingtonpost.com/2012/results").read()
result = re.findall("<span class\\=\\\"obama-popular-votes-pct \\\"\\>([0-9]{3})\\<\\/span\\><\\/span\\>\\&nbsp\\;\\&nbsp\\;&nbsp\\;\\<span class\\=\\\"gop\\\"\\><span class\\=\\\"romney-popular-votes-pct \\\"\\>([0-9]{3})\\<\\/span\\>", html, re.S)
@carloe
carloe / Tools.rb
Created November 4, 2012 00:25
Use text expander to insert your external ip
#!/usr/bin/env ruby -wKU
require 'open-uri'
print (URI.parse('http://icanhazip.com').read).strip
@carloe
carloe / logger.py
Created April 10, 2012 19:13
Python Logger Sample
#! /usr/bin/env python
def init_logger(filename='out.log'):
# Setup the logger
logger = logging.getLogger()
logger.setLevel(logging.DEBUG)
formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s')
fh = logging.FileHandler(filename)
fh.setLevel(logging.DEBUG)
fh.setFormatter(formatter)
@carloe
carloe / hlink.c
Created November 4, 2011 18:16 — forked from anonymous/snippet.c
Easy way to create hard links on os x