Skip to content

Instantly share code, notes, and snippets.

@regularcoder
regularcoder / DelegateNotes.cs
Last active November 7, 2016 21:15
C# delegates
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace CSharpGym
{
/// <summary>
/// Delegates (C# Programming Guide)
/// https://msdn.microsoft.com/en-us/library/ms173171.aspx
@regularcoder
regularcoder / RESTToolingAPI.apxc
Created September 23, 2016 18:28
Force.com Tooling API REST quickstart
//Submit an HTTP GET request
public String getHTTP(String svcURL) {
//HTTP objects
HttpRequest req = new HttpRequest();
req.setHeader('Authorization', 'Bearer ' + UserInfo.getSessionID());
req.setHeader('Content-Type', 'application/json');
String domainUrl = URL.getSalesforceBaseUrl().toExternalForm();
req.setEndpoint(domainUrl + svcURL);
@regularcoder
regularcoder / AnagramsWithinWords.py
Created March 1, 2014 06:57
Anagrams Within Words in Python
#http://regularcoder.wordpress.com/2014/03/01/python-anagrams-within-words/
class AnagramChecker:
#Temporary list that contains the first word. We will remove matching
#characters from here
#Python doesn't insist on explicit declaration of class variables but
#this variable was declared for purposes of clarity
tempFirstWord = []
def checkChar(self, charOfSecondWord):
if charOfSecondWord in self.tempFirstWord:
@regularcoder
regularcoder / randomgen.lisp
Created January 19, 2014 07:33
Park-Miller Minimum Standard Random Number Generator in Common Lisp
(defun get-msrn-naive (x n)
(let ((a 16807) (m 2147483647))
(mod (*
a
;Multiply either by x or recursive call
(if (eq n 1)
x
(get-msrn-naive x (- n 1))))
m)))
@regularcoder
regularcoder / MinimumHD.lisp
Created January 11, 2014 10:50
Minimum Hamming Distance in Common Lisp
;XOR p q => (p V q) ^ !(p ^ q)
(defun xor (p q)
(and
(or p q)
(not (and p q))
)
)
;Represent a number as a boolean list
(defun getbinary (n)
@regularcoder
regularcoder / FletcherChecksum.cs
Created January 4, 2014 11:59
Fletcher's checksum in C#
/*
* Created by SharpDevelop.
* Date: 1/4/2014
* Time: 5:15 PM
*
*
*/
using System;
using System.Text;
using System.Collections.Generic;
@regularcoder
regularcoder / Heap.cs
Created August 26, 2013 13:31
Heapsort in C#
/*
* Created by SharpDevelop.
* Date: 8/15/2013
* Time: 6:33 PM
*
*
*/
using System;
using System.Collections.Generic;
@regularcoder
regularcoder / IOHelper.cs
Last active December 17, 2015 18:19
Binary search in C#
/*
* Created by SharpDevelop.
* Date: 5/26/2013
* Time: 4:04 PM
*
*
*/
using System;
using System.Collections.Generic;
@regularcoder
regularcoder / IOExtensions.cs
Created May 25, 2013 11:46
C# solution for 'Store Credit' from code jam 2010
/*
* Created by SharpDevelop.
* Date: 5/25/2013
* Time: 3:30 PM
*
*/
using System;
using System.IO;
using System.Collections.Generic;
@regularcoder
regularcoder / fizzbuzz.hs
Created May 19, 2013 07:53
FizzBuzz in Haskell
--Tells us if x is divisible by y
divby :: (Integral x) => x -> x -> Bool
divby x y =
(x `mod` y) == 0
--Internal function that returns output for a single number
isfizzbuzz :: (Integral x) => x -> String
isfizzbuzz x
| divby x 3 && divby x 5 = "FizzBuzz"
| divby x 3 = "Fizz"