Skip to content

Instantly share code, notes, and snippets.

View sdarlington's full-sized avatar

Stephen Darlington sdarlington

View GitHub Profile
@sdarlington
sdarlington / EnvironmentVariableSecurityCredentialsProvider.scala
Created December 6, 2019 16:01
Pull credentials from environment variables rather than expecting them to be hard-coded in config file
import org.apache.ignite.plugin.security.{SecurityCredentials, SecurityCredentialsProvider}
class EnvironmentVariableSecurityCredentialsProvider extends SecurityCredentialsProvider {
override def credentials(): SecurityCredentials = new SecurityCredentials(sys.env("IGNITE_USERNAME"), sys.env("IGNITE_PASSWORD"))
}
import UIKit
// Is there a way to "turn off" the Playground on certain lines? Not the same as changing the
// compilation to "manual" -- it's not the compilation that takes the time.
struct SomeThing : Hashable {
let x : Int
// This line gets updated 22299 times... which takes forever despite showing nothing interesting!
var hashValue: Int { get { return x } }
@sdarlington
sdarlington / gist:3fb7be935862416a109b
Created December 1, 2014 16:53
Find the most recently edited project or workspace and open it
mdfind "(kMDItemContentType =='com.apple.xcode.project') || (kMDItemContentType == 'com.apple.dt.document.workspace') " -0 | xargs -0 ls -t | head -1 | cut -f1 -d: | xargs open
@sdarlington
sdarlington / NSManagedObjectContext+ParentContextHelper.m
Last active August 29, 2015 14:04
Using parent NSManagedObjectContexts seems like a pain...
@implementation NSManagedObjectContext (ParentContextHelper)
/*
* In sample code I see a lot of stuff like this when dealing with nested (parent) managed object contexts:
*
* [moc performBlock:^{
* NSError* error = nil;
* [moc save:&error];
*
* [moc.parentContext performBlock:^{
-- Haskell version of groupWhen
-- http://fssnip.net/6A
--
-- Seq.groupWhen isOdd [3;3;2;4;1;2] = seq [[3]; [3; 2; 4]; [1; 2]]
testList = [3, 3, 2, 4, 1, 2]
groupWhen f [] = []
groupWhen f (x:xs) = ( (x : takeWhile notf xs) : groupWhen f (dropWhile notf xs))
where notf x = not (f x)
@sdarlington
sdarlington / fizzbuzz.swift
Last active August 29, 2015 14:03
FizzBuzz
import Foundation
func genericFizzBuzz<T> (number:T, tests:Array<(T)->String?>) -> String {
// Run each of the defined test replacements
let out = tests.map { t in t(number) }
// convert the nil's to empty strings
.map { v in v ?? "" }
// Concatenate all the replacements together
.reduce("", combine: +)
#!/bin/ksh
targetName="$1"
# Thanks to http://stackoverflow.com/a/13871762/75245 for help with the parsing.
relativeInfoPlistLocation=$(/usr/bin/xcrun xcodebuild -showBuildSettings -target ${targetName} 2>/dev/null | awk -F= '/INFOPLIST_FILE/ { print $2; }')
absoluteInfoPlistLocation=${PROJECT_DIR}/$relativeInfoPlistLocation
version=$(/usr/libexec/Plistbuddy -c 'Print :CFBundleShortVersionString' $absoluteInfoPlistLocation)
@sdarlington
sdarlington / quicksort.xmlf
Created May 6, 2011 09:58
Quicksort implementation for Sybase Aleri (SPLASH)
// Pretty literal implementation of the quick sort documented on Wikipedia
// http://en.wikipedia.org/wiki/Quicksort
// Datatypes can trivially be changed to others
int32 quicksort_double (vector(double) data) {
quicksort_internal_double (data, 0, size(data) - 1);
}
int32 quicksort_internal_double (vector(double) data, int32 vleft, int32 vright) {
if (vright > vleft) {
@sdarlington
sdarlington / bubblesort.xmlf
Created May 6, 2011 09:56
Bubblesort implementation for Sybase Aleri (SPLASH)
int32 bubble_sort_double (vector(double) data) {
int32 v_len := size(data);
int32 v_outer := 0;
while (v_outer < v_len) {
int32 v_curr := 1;
while (v_curr < v_len - v_outer) {
if (data[v_curr - 1] > data[v_curr]) {
swap_double (data, v_curr, v_curr - 1);
}
v_curr++;
@sdarlington
sdarlington / heapsort.xmlf
Created May 6, 2011 09:53
Heapsort implementation for Sybase Aleri (SPLASH)
// Pretty literal implementation of the heap sort documented on Wikipedia
// http://en.wikipedia.org/wiki/Heapsort
// Datatypes can trivially be changed to others
int32 heap_sort_double (vector(double) data) {
heapify_double(data);
int32 v_end := size(data) - 1;
while (v_end > 0) {
swap_double (data,v_end,0);