Skip to content

Instantly share code, notes, and snippets.

@pauldambra
pauldambra / checkout-kata.exs
Created December 29, 2015 15:33
the checkout kata in elixir
defmodule Checkout do
defstruct [
basket: %{A: 0, B: 0, C: 0, D: 0}
]
def scan(checkout, code) do
new_value = checkout.basket[code] + 1
%{checkout | basket: Map.put(checkout.basket, code, new_value)}
end
@pauldambra
pauldambra / CodeReviewExercise
Last active January 16, 2020 08:54
For a Code Review exercise
using System.Collections.Generic;
using System.Linq;
namespace CodeReviewExercise
{
using System;
using Serilog;
public class Customer
{
@pauldambra
pauldambra / gist:cc364759476076779bcd
Created February 16, 2015 23:27
Sorting some data with ReactJS
var PayTable = React.createClass({
getInitialState: function() {
return {
sortDirection: 'descending',
data: this.props.payYears.sort(sortDescending)
};
},
sortData: function() {
if(this.state.sortDirection==='descending') {
this.setState({
@pauldambra
pauldambra / gist:e3fb07f73e151152fa3c
Created February 1, 2015 21:00
make and operate on lots of classes and structs
using System;
using System.Collections.Generic;
using ClassOrStruct;
namespace Runner
{
class Program
{
private static readonly Random Random = new Random();
private const int Capacity = 25000000;
'use strict';
var less=require('less');
var fs = require('fs');
var getTree = function(filePath, callback) {
var parser = new(less.Parser)();
fs.readFile(filePath, function (err, data) {
if (err) callback(err);
Image resizer diagnostic sheet 14/08/2013 12:19:32
2 Issues detected:
(Warning): To potentially see additional errors here, perform an image resize request.
(Warning): NoCache is only for development usage, and cannot scale to production use.
Add DiskCache or CloudFront for production use
@pauldambra
pauldambra / RavenDB Index Test
Last active December 14, 2015 07:38
Trying to understand why I suck at making RavenDB indexes
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using Raven.Client;
using Raven.Client.Embedded;
using Raven.Client.Indexes;
using Raven.Client.Listeners;
using Xunit;
@pauldambra
pauldambra / gist:1600391
Created January 12, 2012 13:03
Edited Register Model
[HttpPost]
public ActionResult Register(RegisterModel model)
{
if (ModelState.IsValid)
{
// Attempt to register the user
MembershipCreateStatus createStatus;
Membership.CreateUser(model.UserName, model.Password, model.Email, null, null, true, null, out createStatus);
if (createStatus == MembershipCreateStatus.Success)
@pauldambra
pauldambra / gist:1600372
Created January 12, 2012 13:02
Edited RegisterModel
public class RegisterModel
{
[Required]
[Display(Name = "User name")]
public string UserName { get; set; }
[Required]
[DataType(DataType.EmailAddress)]
[Display(Name = "Email address")]
public string Email { get; set; }
@pauldambra
pauldambra / gist:1600349
Created January 12, 2012 12:57
add custom profile class to web.config profile
<profile defaultprovider="DefaultProfileProvider" inherits="AcrHack.Models.CustomProfile"/>