Skip to content

Instantly share code, notes, and snippets.

View leegould's full-sized avatar
🏠
Working from home

Lee Gould leegould

🏠
Working from home
View GitHub Profile
@leegould
leegould / reverseint.py
Created November 23, 2016 20:45
Reverse an int
class Solution(object):
def reverse(self, x):
"""
:type x: int
:rtype: int
"""
result = 0;
if x > 0:
result = int(str(x)[::-1])
else:
@leegould
leegould / longest_palindrome.js
Created November 22, 2016 21:59
Longest palindrome
/**
* @param {string} s
* @return {string}
*/
var longestPalindrome = function(s) {
var longest = s[0];
for(var i = 0; i < s.length;i++){
palen = '';
var j = -1;
var k = -1;
using System.Collections.Generic;
using System.Linq;
using Xunit;
namespace IsBST
{
public class BSTTester
{
public static bool IsBST(Node root)
{
@leegould
leegould / MemoryCacheExtensions.cs
Created March 2, 2015 10:55
Memory Cache Extensions
/// <summary>
/// Extensions for memory cache.
/// </summary>
public static class MemoryCacheExtensions
{
/// <summary>
/// Add result to memory cache.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="cache"></param>
import random
import string
minLen = 3
maxLen = 8
vowels = ['a', 'e', 'i', 'o', 'u']
consonantExclude = ['q']
consonants = [a for a in string.ascii_lowercase if a not in vowels and a not in consonantExclude]
charpairs = ['qu', 'th', 'ch']
@leegould
leegould / jquery.newguid.js
Last active July 15, 2018 06:46
Jquery plugin for creating a new guid.
/* Jquery function to create guids.
* Guid code from
* http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript
*/
(function ( $ ) {
$.fn.newguid = function () {
this.val('xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) { var r = Math.random() * 16 | 0, v = c == 'x' ? r : r & 0x3 | 0x8; return v.toString(16); }));
return this;
};
@leegould
leegould / Fakes.cs
Last active June 11, 2021 10:48
Faking ODataQueryOptions for WebAPI
public static class Fakes
{
public static ODataQueryOptions ODataQueryOptionsFake(Type itemtype, HttpRequestMessage request, string expandValue, string inlineCountValue)
{
var odataQueryOptionsFake = new ODataQueryOptions(Substitute.For<ODataQueryContext>(Substitute.For<IEdmModel>(), itemtype), request);
var rawValuesFake = new ODataRawQueryOptions();
typeof(ODataRawQueryOptions).GetProperty("Expand").SetValue(rawValuesFake, expandValue);
typeof(ODataRawQueryOptions).GetProperty("InlineCount").SetValue(rawValuesFake, inlineCountValue);
typeof(ODataQueryOptions).GetProperty("RawValues").SetValue(odataQueryOptionsFake, rawValuesFake);
return odataQueryOptionsFake;
@leegould
leegould / warmup.ps1
Created December 10, 2012 14:18
Cache warming script for pre iis 7.5
<#
.SYNOPSIS
This is a powershell script to ping a website and log the response
.DESCRIPTION
The script will send a web request to the site specified in the parameters, and log to the file specified in the parameters (if any)
.EXAMPLE
./api.warmup.ps1 -url http://api.mysite.com/ -logFile logfile.txt
@leegould
leegould / DictionaryExtensions.cs
Created November 6, 2012 10:48
Dictionary Extension Methods
public static class DictionaryExtensions
{
/// <summary>
/// Add a range of items to a dictionary.
/// </summary>
/// <typeparam name="T">type</typeparam>
/// <typeparam name="TU">type</typeparam>
/// <param name="source">the dictionary</param>
/// <param name="dictionary">the range to be added</param>
public static void AddRange<T, TU>(this IDictionary<T, TU> source, IDictionary<T, TU> dictionary)
@leegould
leegould / MessageWriter.cs
Created April 27, 2012 14:10
Message Writer
using System;
namespace Utils
{
public abstract class MessageWriter
{
public Action<string, object[]> Writer { get; set; }
/// <summary>
/// If the Writer method is not null, writes the message to it.