Skip to content

Instantly share code, notes, and snippets.

@fabb
fabb / failure_test.hs
Created April 19, 2011 19:57
Some failure catching with the failure package
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE DeriveDataTypeable #-}
import Control.Exception (Exception)
import Data.Typeable (Typeable)
import Control.Failure
@fabb
fabb / gource-multiple-repositories.sh
Created September 7, 2012 08:45 — forked from anonymous/gource-multiple-repositories.sh
Generates gource video out of multiple repositories.
#!/usr/bin/env bash
# Generates gource video (h.264) out of multiple repositories.
# Pass the repositories in command line arguments.
# Example:
# <this.sh> /path/to/repo1 /path/to/repo2
i=0
for repo in $*; do
# 1. Generate a Gource custom log files for each repo. This can be facilitated by the --output-custom-log FILE option of Gource as of 0.29:
logfile="$(mktemp /tmp/gource.XXXXXX)"
//some time, frc section may be need section offset
@objc public protocol MFetchedResultsControllerOffsetSectionDelegate{
func offsetSection() -> Int
}
class MFetchedResultsController: NSFetchedResultsController, NSFetchedResultsControllerDelegate {
weak var viewController: UIViewController? //UITableViewController UICollectionViewController
weak var scrollView: UIScrollView? //TableView CollectionView
weak var offsetSectionDelegate: MFetchedResultsControllerOffsetSectionDelegate?
@fabb
fabb / gist:5014867
Last active December 14, 2015 02:39
Seemingly buggy behavior with PySCXML: the second event "f" is not received in most executions
import time
from scxml.pyscxml import StateMachine
import logging
logging.basicConfig(level=logging.NOTSET) # show detailed debug info
xml = '''
<scxml xmlns="http://www.w3.org/2005/07/scxml" version="1.0" datamodel="python" initial="S1">
<state id="S1">
<onentry>
@fabb
fabb / gist:5019653
Created February 23, 2013 13:03
Issue #4 in PySCXML: transition also exits & enters again unaffected states
import time
from scxml.pyscxml import StateMachine
import logging
logging.basicConfig(level=logging.NOTSET) # show detailed debug info
xml = '''
<scxml xmlns="http://www.w3.org/2005/07/scxml" version="1.0">
<state id="main">
<onentry>
import Foundation
struct Song {
let title: String
let length: Float
func withAddedAdvertisement() -> Song {
return Song(title: self.title + " plus commercial", length: self.length + 10)
}
}
import Foundation
struct Song {
var title: String
var length: Float
mutating func addAdvertisement() {
self.title += " plus commercial"
self.length += 10
}
@fabb
fabb / gist:5908388
Created July 2, 2013 10:51
format current NSDate as ISO8601 string despite user's Calendar or 24-Hour-Format setting
- (NSString *)currentGregorianISO8601Date {
NSDate *requestDate = [NSDate date];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ssZ"];
// WORKAROUND http://openradar.appspot.com/radar?id=1110403
[dateFormatter setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"US"]];
// translate to Gregorian calendar if other calendar is selected
@fabb
fabb / archive_ipa.sh
Created November 1, 2014 12:39
Script to archive an ipa from commandline - depends on xctool
#!/bin/bash
set -x
cd ${0%/*}/..
# codesigning and choosing of provisioning profile is configured via project settings and is dependent of build config
: ${BUILD_NUMBER:?"Need to set BUILD_NUMBER"}
WORKSPACE=<yourworkspace>.xcworkspace
@fabb
fabb / TheAbyss.h
Last active October 25, 2017 10:32 — forked from anonymous/TheAbyss.h
// TheAbyss.h
+ (NSString *)greetingMessageFromTheOtherworld;
// TheAbyss.m
+ (NSString *)greetingMessageFromTheOtherworld {
return nil;
}
// LonesomeWanderer.swift
TheAbyss.greetingMessageFromTheOtherworld().isEmpty