Skip to content

Instantly share code, notes, and snippets.

@ungood
ungood / spotit.py
Last active August 29, 2015 14:06 — forked from anonymous/spotit.py
import itertools
import argparse
letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
class Card:
def __init__(self, symbols):
self.symbols = frozenset(symbols)
self.name = "".join(symbols)
@ungood
ungood / gist:8153540
Created December 27, 2013 22:28
load modules in a package
def load_modules(package):
for importer, name, is_package in pkgutil.iter_modules([package]):
fullname = package + '.' + name
if not is_package:
loader = importer.find_module(fullname)
yield loader.load_module(fullname)
@ungood
ungood / gist:5632446
Created May 23, 2013 02:37
Very simple linked list example
typedef struct {
string name;
node* next;
} node;
node* first = null;
void append(string name) {
new_node = new linked_list {
name = name,
// Store a deck in a bit array by the following algorithm:
// value := pick[0];
// value = value * 51 + second pick
// value = value * 50 + third pick
// ..
// value = value * 1 + 52nd pick
// The first pick is pick[0]
BigInt StoreDeck(params int[] picks) {
BigInt value = pick[0];
for(int i = 1; i < picks.Length; i++) {
@ungood
ungood / tmux_cheatsheet.markdown
Created November 29, 2012 22:04 — forked from henrik/tmux_cheatsheet.markdown
tmux cheatsheet

tmux cheatsheet

As configured in my dotfiles.

start new:

tmux

start new with session name:

@ungood
ungood / gist:3658896
Created September 6, 2012 17:44
Example Ninject Binding
using System.Web;
using BBCom.Gotham.Domain;
using BBCom.Gotham.Service;
using GothamMVC3.Helpers;
using GothamMVC3.Navigation;
using Ninject;
using Ninject.Modules;
using Ninject.Web.Common;
using Ninject.Extensions.Conventions;
using Telerik.Web.Mvc;
@ungood
ungood / gist:3534468
Created August 30, 2012 17:31
Simple Console App example
public class Program
{
public static void Main()
{
// Register
using(var kernel = ConfigureKernel())
{
// Resolve
var program = kernel.Get<Program>();
program.Run();
@ungood
ungood / gist:3085778
Created July 10, 2012 19:47
LINQ Mandelbrot Calculation
public class GenerateAndCountCalculator : IMandelbrotCalculator
{
public int CalculatePoint(Complex c, int maxIterations)
{
return Generate(Complex.Zero, z => (z * z) + c)
.TakeWhile(z => z.Magnitude <= 2)
.Take(maxIterations)
.Count();
}
@ungood
ungood / BigIntegerExtensions.cs
Created June 29, 2012 15:01
Silly Puzzle solved for multiple bases
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Text;
namespace ConsoleApplication4
{
public static class BigIntegerExtensions
{
@ungood
ungood / gist:2500145
Created April 26, 2012 14:53
Example of why methods are better
// This is really elegant with methods, but really, really ugly with query expression
public IQueryable<User> SearchUsers(string firstName, string lastName)
{
var query = getUserQuery();
if(!string.IsNullOrEmpty(firstName))
query = query.Where(user => user.FirstName == firstName);
if(!string.IsNullOrEmpty(lastName))
query = query.Where(user => user.LastName == lastName);