Skip to content

Instantly share code, notes, and snippets.

@daveharris
daveharris / Challenge 1.md
Last active May 11, 2020
Coding Challenge
View Challenge 1.md

In the programming language of your choice, write a program that accepts an array of words, and calculates the number of vowels. For example, Given:

['hello', 'world']

Produces:

a: 0
e: 1
i: 0
@daveharris
daveharris / bashmarks-homebrew.rb
Created Nov 24, 2014
Bashmarks Homebrew Install Formula
View bashmarks-homebrew.rb
require "formula"
class Bashmarks < Formula
homepage "https://github.com/huyng/bashmarks"
url "https://github.com/daveharris/bashmarks/archive/1.0.tar.gz"
sha1 "53010ce4f613e5e30070ceae01eee5526f3063b2"
version "1.0"
def install
system "make", "install"
@daveharris
daveharris / modularise.rb
Created Feb 19, 2014
Add "Module MyModule" to all ruby files
View modularise.rb
Dir["**/*.rb"].each do |file|
contents = IO.readlines(file)
open(file, "w") do |f|
f.puts "module MyModule\n"
contents.each { |line| f.write " #{line}" }
f.puts "\nend"
end
end
@daveharris
daveharris / TestResults.java
Created Oct 23, 2013
Ruby and Java comparisons for taking a file of results and calculating average, minimum and maximum scores and whether the test should be scaled or not
View TestResults.java
import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Scanner;
public class TestResults {
public static void main(String[] args) throws FileNotFoundException {
ArrayList<Integer> scores = new ArrayList<Integer>();
Scanner scanner = new Scanner(new File("test_results.txt")).useDelimiter("\\n");;
@daveharris
daveharris / Java delete_if.java
Last active Dec 14, 2015
Differences between Java and Ruby
View Java delete_if.java
Set<Kitten> kittens = KittenDaoImpl.all();
Iterator iter = kittens.iterator();
while(iter.hasNext()) {
Kitten kitten = iter.next();
if (kitten.isCuteAndAdorable()) {
iter.remove();
}
}
View gist:581816

I have found the layout of SWT rather esoteric, and the javadoc is really bad, it doesn't say what the meaning of the argument is, so you have stuff like: GridLayout gridLayout = new GridLayout(2, true); which means you have 2 columns and they are each of equal width. To make this more readable/understandable, I propose two otions...

Option 1 - Use named paramaters

We can name the parameters like so;

int numColumns = 2;

boolean makeColumnsEqualWidth = false;