Skip to content

Instantly share code, notes, and snippets.

View dvdsgl's full-sized avatar
🦋
Gliding

David Siegel dvdsgl

🦋
Gliding
View GitHub Profile
@dvdsgl
dvdsgl / UserStateObserver.cs
Created January 2, 2011 04:38
This is why MonoMac is hot
using System;
using System.Collections.Generic;
using MonoMac.Foundation;
using MonoMac.AppKit;
using MonoMac.ObjCRuntime;
using Cadenza;
namespace MySecretApp {
private static IEnumerable<TSource> SkipWhileImpl<TSource>(
IEnumerable<TSource> source,
Func<TSource, bool> predicate)
{
return SkipWhileImpl (source, (element, index) => predicate (element));
}
@dvdsgl
dvdsgl / nub_files.hs
Created June 1, 2011 03:54
Delete duplicate files in Haskell
#!/usr/bin/runhaskell
import Data.List
import Control.Monad
import System.Process (readProcess)
import System.Environment (getArgs)
import System.Directory (doesFileExist, removeFile)
@dvdsgl
dvdsgl / nub_files.rb
Created June 1, 2011 03:54
Delete duplicate files in Ruby
#!/usr/bin/ruby
ARGV.group_by {
|file| `md5 #{file}`.split.last
}.values.map {
|dups| dups.drop 1
}.flatten.each {
|dup| File.delete dup
}
@dvdsgl
dvdsgl / NSApplicationExtensions.cs
Created June 29, 2011 17:14
Extensions to NSApplication for hiding Dock icon and relaunching.
using System;
using System.IO;
using System.Diagnostics;
using MonoMac.AppKit;
using MonoMac.Foundation;
namespace Awareness
{
public static class NSApplicationExtensions
@dvdsgl
dvdsgl / .bashrc
Created January 24, 2012 23:17
SSH Agent Config
SSH_ENV="$HOME/.ssh/environment"
# start the ssh-agent
function start_agent {
echo "Initializing new SSH agent..."
# spawn ssh-agent
ssh-agent | sed 's/^echo/#echo/' > "$SSH_ENV"
echo succeeded
chmod 600 "$SSH_ENV"
. "$SSH_ENV" > /dev/null
fs = require 'fs'
class MyClass
# Trying to create middleware with access to class members.
withData: (cb) ->
return cb @__data if @__data?
fs.readFile 'datafile.json', (err, json) =>
throw err if err?
@__data = JSON.parse json
findRoots 0 b c = Nothing
findRoots a b c = Just ((-b + d) / 2*a, (-b - d) / 2*a)
where d = sqrt (b^2 - 4*a*c)
main = print (findRoots 1 6 8)
@dvdsgl
dvdsgl / Quadratic.hs
Created March 26, 2012 18:30
Made easier to 'parse' for Non-haskellers
-- findRoots is a function that takes 3 Doubles and maybe returns a tuple of doubles.
-- Here's its signature, which can be omitted because Haskell infers it:
findRoots :: Double -> Double -> Double -> Maybe (Double, Double)
-- In a C-like language with parameterized types, the type signature might look like:
--
-- static Maybe<Tuple<double,double>> findRoots(double a, double b, double c);
--
-- Maybe is Haskell's 'nullable type'; values of type Maybe t can be thought of as lists
-- containing exactly zero or one value of type t. So, a Maybe Double is either zero or
// Register an API key in your AppDelegate's FinsihedLaunching method:
// GMSServices.ProvideAPIKey ("Your API key.");
GMSMapView mapView;
public override void ViewDidLoad ()
{
base.ViewDidLoad ();
// Create the map view, framing Xamarin headquarters