This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Person A flips and Person B chooses "heads" or "tails". | |
# Person B wins if their choice matches the flip, otherwise | |
# person A wins. | |
defmodule CoinToss do | |
def run_simulation(num_people) do | |
counterPid = spawn(__MODULE__, :counter_loop, [0, 0]) | |
Process.register(counterPid, :counter) | |
people = create_people(num_people) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ConvertingSignedBytes { | |
public static void main(String[] args) { | |
byte x = (byte) 37; | |
byte y = (byte) 150; | |
printByte(x); | |
printByte(y); | |
} | |
public static void printByte(byte b) { | |
int value; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; gorilla-repl.fileformat = 1 | |
;; ** | |
;;; # Plotting some evolved sine results | |
;;; | |
;;; I decided to play with [Gorilla Repl](http://gorilla-repl.org) to try to plot some of the evolved Sine results just to make sure we were solving the problem we thought we were solving. | |
;;; | |
;;; The short version is that Gorilla Repl was quite excellent, and we are indeed solving the sine problem :-) | |
;;; | |
;;; One of the nifty things is that Clojure allowed me to define the symbol % to be protected division, so we can paste in functions straight from ECJ and run them without having to do any annoying search/replace action to get things in a format that our graphing tool can process. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Counter { | |
private int count = 0; | |
public int getCount() { | |
return count ; | |
} | |
/** | |
* The "synchronized" keyword is crucial here; removing it will lead to serious |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class IncorrectSynchronizedIncrement implements Runnable { | |
private static final int NUM_THREADS = 4; | |
private static final int NUM_INCREMENTS = 10000; | |
private static int count = 0; | |
public static void main(String[] args) throws InterruptedException { | |
Thread[] threads = new Thread[NUM_THREADS]; | |
for (int i=0; i<NUM_THREADS; ++i) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class SimpleIncrement implements Runnable { | |
private static final int NUM_THREADS = 4; | |
private static final int NUM_INCREMENTS = 10000; | |
private static int count = 0; | |
public static void main(String[] args) throws InterruptedException { | |
Thread[] threads = new Thread[NUM_THREADS]; | |
for (int i=0; i<NUM_THREADS; ++i) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0"?> | |
<company> | |
<employee> | |
<firstname>Tom</firstname> | |
<lastname>Cruise</lastname> | |
</employee> | |
<employee> | |
<firstname>Paul</firstname> | |
<lastname>Enderson</lastname> | |
</employee> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems/package' | |
require 'zlib' | |
# This is intended as an example of how to use GzipReader and TarReader to process a | |
# collection of gzipped tar files (.tgz files or .tar.gz files). Searching (as of Sept 2013) | |
# for documentation of these libraries and examples of their use isn't terribly satisfactory, | |
# so I thought I'd write up an example in the hopes that people find it helpful. | |
# This assumes that a set of GZipped Tar files are provided as command line arguments, | |
# and that these zipped tar files contain log data that includes (among other things) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class RomanNumeralConverter { | |
def mappings = [[[1000 , "M"], [500 , "D"], [100 , "C"]], | |
[[100 , "C"], [50 , "L"], [10 , "X"]], | |
[[10 , "X"], [5 , "V"], [1 , "I"]]] | |
def convert(integer) { | |
String result = "" | |
def pair = handleDigit("M","D", "C", 100, result, integer) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class DictionaryReplacer { | |
def replace(string, dictionary){ | |
def returnValue | |
if (string.size() < 2){ | |
returnValue = string | |
} | |
else if (string[0]!='$'){ | |
def firstDollar = string.indexOf('$') | |
if (firstDollar == -1) { |