Skip to content

Instantly share code, notes, and snippets.

View joelmartinez's full-sized avatar
👨‍🚀
Fighting Entropy

Joel Martinez joelmartinez

👨‍🚀
Fighting Entropy
View GitHub Profile
@joelmartinez
joelmartinez / GameOfLife.cs
Created September 5, 2011 03:24
Conway's Game Of Life in C#
using System;
using System.Threading.Tasks;
namespace Life
{
public class LifeSimulation
{
private bool[,] world;
private bool[,] nextGeneration;
private Task processTask;
@joelmartinez
joelmartinez / gist:1240580
Created September 25, 2011 13:03
Minimal C#/MongoDb HowTo
MongoServer server = MongoServer.Create("mongodb://TheUserName:ThePassword@The.Url.Com:12345/TheDatabaseId");
MongoDatabase mongo = server.GetDatabase("<TheDatabaseId>");
var employees = mongo.GetCollection<TheClass>("TheCollectionName");
var cursor = employees.FindAllAs<TheClass>();
var item = cursor.FirstOrDefault();
....
@joelmartinez
joelmartinez / gist:1283275
Created October 13, 2011 03:19
Jint for WP7 Snippet
var engine = new JintEngine();
engine.SetFunction("alert", new Action<string>(t => MessageBox.Show(t)));
engine.Run("alert('Hello World, from dynamically interpereted JavaScript on WP7!')");
@joelmartinez
joelmartinez / ImageDownloader.java
Created December 8, 2011 20:42
Android ImageDownloader (from random StackOverflow thread)
package com.your.project;
import java.io.IOException;
import java.io.InputStream;
import java.lang.ref.SoftReference;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.util.Collections;
import java.util.HashMap;
@joelmartinez
joelmartinez / gist:1929080
Created February 28, 2012 03:15
hashing a string in android
/** pieced together from http://www.androidsnippets.com/create-a-md5-hash-and-dump-as-a-hex-string */
public String md5(String s) {
try {
// Create MD5 Hash
MessageDigest digest = java.security.MessageDigest.getInstance("MD5");
digest.update(s.getBytes());
byte messageDigest[] = digest.digest();
// Create Hex String
StringBuffer hexString = new StringBuffer();
@joelmartinez
joelmartinez / XmlMapParser.java
Created May 10, 2012 20:50
Parse an iOS plist with a dict into a java HashMap<String, ArrayList<String>>
package cyborg;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import android.content.Context;
@joelmartinez
joelmartinez / UserSettings.cs
Created October 13, 2012 04:07
dynamic NSUserDefaults for MonoMac
using System;
using System.Dynamic;
using MonoMac.Foundation;
namespace CodeCube
{
public class UserSettings : DynamicObject
{
NSUserDefaults defaults = NSUserDefaults.StandardUserDefaults;
@joelmartinez
joelmartinez / gist:4613721
Created January 23, 2013 21:31
A simple category on object to let you perform a block after a delay, rather than having to pass in a selector reference
// http://stackoverflow.com/a/4007066/5416
@implementation NSObject (PerformBlockAfterDelay)
- (void)performBlock:(void (^)(void))block
afterDelay:(NSTimeInterval)delay
{
block = [[block copy] autorelease];
[self performSelector:@selector(fireBlockAfterDelay:)
withObject:block
@joelmartinez
joelmartinez / program.cs
Created September 5, 2013 18:26
simple proof of concept to generate permutations from two lists ... First, there needed to be every permutation for the platforms list. Second was a permutation of the platform and tags lists.
using System;
using System.Linq;
using System.Collections.Generic;
namespace Permutations
{
class MainClass
{
public static void Main (string[] args)
{
@joelmartinez
joelmartinez / iter.cs
Created August 1, 2014 21:26
A simple extension method that gives you the "Iter" function from F#
static class x10 {
public static IEnumerable<T> Iter<T>(this IEnumerable<T> list, Action<T> action) {
foreach (var n in list) {
action (n);
yield return n;
}
}
}