Snipplr - rtperson
http://snipplr.com/users/rtperson
Recent snippets posted on Snipplr.comen-usMon, 29 Aug 2016 07:00:15 GMT(XML) Create a Webservice Client using Maven ws-import Plugin
http://snipplr.com/view/72094/create-a-webservice-client-using-maven-wsimport-plugin/
Use this if you need Maven to automatically create a SOAP client for you. ]]>Sun, 11 Aug 2013 12:14:12 GMThttp://snipplr.com/view/72094/create-a-webservice-client-using-maven-wsimport-plugin/(C) Radix Conversion In C
http://snipplr.com/view/68873/radix-conversion-in-c/
How to convert an integer from base 10 to a string of base x (where x ]]>Sun, 02 Dec 2012 12:45:17 GMThttp://snipplr.com/view/68873/radix-conversion-in-c/(C) Palindrome Check In C
http://snipplr.com/view/68872/palindrome-check-in-c/
A palindrome is a string that reads the same both backwards and forwards. Famous examples are "Madam I'm Adam" or "Able was I ere I saw Elba". This function checks that a given string reads the same backwards and forwards. (requires including stdbool.h) ]]>Sun, 02 Dec 2012 12:43:58 GMThttp://snipplr.com/view/68872/palindrome-check-in-c/(C) Ternary Counting In C
http://snipplr.com/view/68870/ternary-counting-in-c/
Here's a fairly useless but fun piece of code: counting in base 3. This takes in a number of digits and counts up in ternary. Be warned, though. The algorithm is (for obvious reasons) O(n^3), where n is the number of digits. Actually probably theta(n^3), since n^3 is both the upper and lower bound. Either way, it spits out 531,441 possibilities for 12 digits, so be careful not to run it on too many digits. ]]>Sun, 02 Dec 2012 12:41:23 GMThttp://snipplr.com/view/68870/ternary-counting-in-c/(PL/SQL) How To Change The Value Of A Sequence In PL/SQL
http://snipplr.com/view/68869/how-to-change-the-value-of-a-sequence-in-plsql/
I'm pretty meh about Oracle's PL/SQL, but its inability to reference and change sequences has been pretty frustrating over the years. Until now. Thanks to the Puget Sound Oracle Users Group's website (psoug.org) for showing me how to do this. ]]>Sun, 02 Dec 2012 12:39:22 GMThttp://snipplr.com/view/68869/how-to-change-the-value-of-a-sequence-in-plsql/(C++) Calendar Calculation in C++
http://snipplr.com/view/68867/calendar-calculation-in-c/
Brute-force calculation of any date. Includes some very tricky rules for modern-day Gregorian calendar. ]]>Sun, 02 Dec 2012 12:36:50 GMThttp://snipplr.com/view/68867/calendar-calculation-in-c/(C++) Using a Map for Dynamic Programming in C++
http://snipplr.com/view/68866/using-a-map-for-dynamic-programming-in-c/
Really DP-lite. Memoize the solution for a recursive problem so it can be looked up on subsequent iterations. ]]>Sun, 02 Dec 2012 12:34:58 GMThttp://snipplr.com/view/68866/using-a-map-for-dynamic-programming-in-c/(Haskell) Linked List in C
http://snipplr.com/view/68865/linked-list-in-c/
I bit of overkill for USACO's "Milk2" algorithm training problem. This problem would be better suited to an interval tree, but here it is. ]]>Sun, 02 Dec 2012 12:32:20 GMThttp://snipplr.com/view/68865/linked-list-in-c/(Haskell) Binary Search in Haskell
http://snipplr.com/view/68840/binary-search-in-haskell/
Improved version, using lenses instead of the dangerous (!!) operator for list access. ]]>Fri, 30 Nov 2012 14:16:50 GMThttp://snipplr.com/view/68840/binary-search-in-haskell/(Java) Scaling Values into a range between 0 and 1
http://snipplr.com/view/66636/scaling-values-into-a-range-between-0-and-1/
You have to use float or double for the returned value, since the scale occurs in a continuous function. ]]>Fri, 10 Aug 2012 11:35:33 GMThttp://snipplr.com/view/66636/scaling-values-into-a-range-between-0-and-1/(Java) Quicksort in Java, with Enforced Suckitude
http://snipplr.com/view/64808/quicksort-in-java-with-enforced-suckitude/
It's no fun implementing QuickSort unless you can force it out of its blister-fast, O(n log n) speed and humiliate it with its worst-case, O(n^2) runtime. So that's what I set out to do.
My naive partition simply pivots around the low item, but my randomized partition defeats the sucky inputs by choosing a random pivot. (If you're interested in checking out a QuickSort which naively partitions until it hits an attempt to get it to run in quadratic time, check out IntroSort -- which simply fails over to Merge Sort when it exceeds its optimal recursion depth.) ]]>Tue, 08 May 2012 00:02:25 GMThttp://snipplr.com/view/64808/quicksort-in-java-with-enforced-suckitude/(C) Two Binary Search Functions in C
http://snipplr.com/view/63046/two-binary-search-functions-in-c/
Two versions of binary search -- one recursive, one iterative -- for an array of strings.
Both assume that your array index fits within an integer. ]]>Sat, 04 Feb 2012 02:45:29 GMThttp://snipplr.com/view/63046/two-binary-search-functions-in-c/(Haskell) Haskell 99 Problems - Problem 23
http://snipplr.com/view/58582/haskell-99-problems--problem-23/
problem 23, Extract a given number of randomly selected elements from a list.
Example:
Prelude System.Random>rnd_select "abcdefgh" 3 >>= putStrLn
"eda"
Two problems: 1) How to return a list, and 2) how to sample without duplication ]]>Sat, 10 Sep 2011 07:27:49 GMThttp://snipplr.com/view/58582/haskell-99-problems--problem-23/(Haskell) Haskell 99 Problems, numbers 1 through 9
http://snipplr.com/view/58509/haskell-99-problems-numbers-1-through-9/
I had originally started these problems from #10 (Run-length encoding). I went back and did 1-8 for completeness. ]]>Thu, 08 Sep 2011 00:23:54 GMThttp://snipplr.com/view/58509/haskell-99-problems-numbers-1-through-9/(Haskell) Haskell 99 Problems - Number 20, Arrowed!
http://snipplr.com/view/58144/haskell-99-problems--number-20--arrowed/
problem 20, (*) Remove the K'th element from a list
*Main> removeAt 1 "abcd"
"acd"
Trivial using a pure function. A bit more challenging if you use this problem to work up your Arrow-fu. ]]>Thu, 25 Aug 2011 01:54:30 GMThttp://snipplr.com/view/58144/haskell-99-problems--number-20--arrowed/(Haskell) Haskell 99 Problems - Number 18 and 19
http://snipplr.com/view/58064/haskell-99-problems--number-18-and-19/
Problem 18: Extract a slice from a list.
Given two indices, i and k, the slice is the list containing the elements between the i'th and k'th element of the original list (both limits included). Start counting the elements with 1.
Example:
*Main> slice ['a','b','c','d','e','f','g','h','i','k'] 3 7
"cdefg
9 Problem 19 - Rotate a list N places to the left.
*Main> rotate ['a','b','c','d','e','f','g','h'] 3
"defghabc"
*Main> rotate ['a','b','c','d','e','f','g','h'] (-2)
"ghabcdef"
(This one is so easy it feels like cheating...) ]]>Sun, 21 Aug 2011 01:58:02 GMThttp://snipplr.com/view/58064/haskell-99-problems--number-18-and-19/(Haskell) Haskell 99 Problems - Number 17
http://snipplr.com/view/57981/haskell-99-problems--number-17/
problem 17, Split a list into two parts; the length of the first part is given.
Do not use any predefined predicates. (Meaning no splitAt or take or drop)
*Main> split "abcdefghik" 3
("abc", "defghik") ]]>Thu, 18 Aug 2011 06:50:09 GMThttp://snipplr.com/view/57981/haskell-99-problems--number-17/(Haskell) Haskell 99 Problems - Numbers 15 and 16
http://snipplr.com/view/57971/haskell-99-problems--numbers-15-and-16/
problem 15, Replicate the elements of a list a given number of times.
> repli "abc" 3
"aaabbbccc"
problem 16, Drop every N'th element from a list.
*Main> dropEvery "abcdefghik" 3
"abdeghk" ]]>Thu, 18 Aug 2011 03:59:30 GMThttp://snipplr.com/view/57971/haskell-99-problems--numbers-15-and-16/(Haskell) Haskell 99 Problems - Number 14
http://snipplr.com/view/57921/haskell-99-problems--number-14/
problem 14, Duplicate the elements of a list
> dupli [1, 2, 3]
[1,1,2,2,3,3] ]]>Thu, 18 Aug 2011 01:04:04 GMThttp://snipplr.com/view/57921/haskell-99-problems--number-14/(Haskell) Haskell 99 Problems - Solutions to 11 and 12
http://snipplr.com/view/57309/haskell-99-problems--solutions-to-11-and-12/
problem 11, modified run-length encoding
========================================
If an element has no duplicates, mark it as such.
Example:
encodeModified "aaaabccaadeeee"
[Multiple 4 'a',Single 'b',Multiple 2 'c',
Multiple 2 'a',Single 'd',Multiple 4 'e']
problem 12, Decode a run-length encoded list.
=============================================
Given a run-length code list generated as specified in problem 11. Construct its uncompressed version.
Example:
decodeModified
[Multiple 4 'a',Single 'b',Multiple 2 'c',
Multiple 2 'a',Single 'd',Multiple 4 'e']
"aaaabccaadeeee" ]]>Fri, 29 Jul 2011 08:03:55 GMThttp://snipplr.com/view/57309/haskell-99-problems--solutions-to-11-and-12/