Skip to content

Instantly share code, notes, and snippets.

@hgbrown
hgbrown / LimitingScopeOfVariables.kt
Created August 27, 2019 11:20
Demonstrates the importance of limiting the scope of variables to the smallest possible scope.
package dev.hbrown
/**
* Demonstrates the importance of limiting the scope of a variable using the Sieve of Eratosthenes to find prime numbers
* using a sequence builder. The algorithm is conceptually very easy:
*
* 1. take a list of numbers starting at 2.
* 2. remove the first number, it is prime.
* 3. from the rest of the numbers, remove the first number as well as all the numbers divisible by this prime number.
*
@hgbrown
hgbrown / danger-will-robinson.kts
Created October 27, 2018 04:21
Demonstrates the dangers of mutability in Kotlin. Why you should prefer val to var
#!/usr/bin/env kscript
var factor = 2
fun doubleIt(n: Int) = n * factor
var message = "The factor is $factor"
factor = 0
println(doubleIt(2))
println(message)
@hgbrown
hgbrown / search.groovy
Created December 29, 2013 16:39
GROOVY:Groovy Grape Example with documentation
#!/usr/bin/env groovy
/**
* Demonstrates how to use Grape to grab dependencies for
* Groovy scripts.
*
* Grape stands for the Groovy Adaptable (Advanced) Packaging Engine, and it is a part of the Groovy installation.
* Grape helps you download and cache external dependencies from within your script with a set of simple annotations.
*
* If, in your script, you require an external dependency, that you know is available in a public repository as Maven Central Repository,
@hgbrown
hgbrown / web.xml
Created December 11, 2013 11:06
XML:web.xml for jsf faces configuration
<web-app
version="3.1"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd">
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<servlet>
@hgbrown
hgbrown / generateGroovyGradleProject.groovy
Created August 30, 2013 14:01
GROOVY:Generate Gradle Groovy Project
#!/usr/bin/env groovy
/**
* Simple script to create a Groovy project using Gradle
*/
def console = System.console()
String projectName = console.readLine("What is the name of the project? ")
String projectFolderName = projectName.replaceAll(" ", "-").toLowerCase()
@hgbrown
hgbrown / todo.html
Created August 3, 2013 08:18
HTML:AngularJS:ToDo Example
<!doctype html>
<html ng-app>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.min.js"></script>
<script>
function TodoCtrl($scope) {
$scope.todos = [
{text:'learn angular', done:true},
{text:'build an angular app', done:false}];
@hgbrown
hgbrown / person.html
Created August 3, 2013 08:17
HTML:AngulaJS:Person Example
AngulaJS:Person Example
@hgbrown
hgbrown / helloworld.html
Created August 3, 2013 07:34
HTML:AngularJS Hello World
<!DOCTYPE html>
<html>
<head>
<title>AngularJS: Hello World</title>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.1/angular.min.js"></script>
</head>
<body>
<div ng-app>
<input type="text" ng-model="name" placeholder="Enter your name here..." />
<span ng-show="name">Hello, {{name}}</span>
@hgbrown
hgbrown / pom.xml
Created April 28, 2013 14:54
XML:Cucumber Maven dependencies
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.henry.g.brown</groupId>
<artifactId>CucumberDemo</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
@hgbrown
hgbrown / arquillian.xml
Created April 22, 2013 13:51
XML: Arquillian configuration basic skeleton
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<arquillian xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://jboss.org/schema/arquillian"
xsi:schemaLocation="http://jboss.org/schema/arquillian http://jboss.org/schema/arquillian/arquillian_1_0.xsd">
</arquillian>