Skip to content

Instantly share code, notes, and snippets.

View stpettersens's full-sized avatar

Sam Saint-Pettersen stpettersens

View GitHub Profile
#!/bin/sh
# Build Gaudi
pkg="org/stpettersens/gaudi"
jarF="Gaudi.jar"
echo "Compiling..."
scalac -classpath ./lib -verbose -deprecation -unchecked -d bin src/$pkg/*.scala
echo "Packaging..."
#!/bin/bash
# Build Gaudi
sep=";" # Initially use Windows, ";"
# For Linux, Unix/xBSD - use ":"
if [[ `uname` =~ .*n.*x|.+BSD ]]; then
sep=":"
fi
/*
Hello World in Scala
*/
object HelloWorld {
def main(args: Array[String]) {
println("Hello World!")
}
}
- OR -
#!/bin/bash
echo "y/n?"
read yesno
if [[ $yesno -eq "y" ]]; then
echo "You said yes :)"
else
if [[ $yesno -eq "n" ]]; then
echo "You said no :("
fi
// Begins a line comment
# as used in preprocessor definitions, e.g. #include <io>
() as used in function calls, function definitions, etc.
e.g.
int add(int num1, int num 2) {
return num 1 + num2;
}
/*
Groovy class inheritence demonstration
*/
class Ancestor {
def name
Ancestor() {
name = "Homo erectus"
}
def speak() {
println "I am " + name
sPerson.scala:
class sPerson extends jPerson {
def getName(): String = "Sammy Saint"
}
jPerson.java:
public interface jPerson {
public String getName();
@stpettersens
stpettersens / gist:630359
Created October 16, 2010 22:42
Fantom snippet for running Gaudi process
class GaudiUILogic {
Void invokeGaudi(Str params) {
Process gaudi := sys::Process()
gaudi.command = ["gaudi", params]
gaudi.run()
}
}
@stpettersens
stpettersens / fsm.c
Created November 19, 2010 21:28
Traffic lights FSM
/*
Traffic lights finite state machine (FSM)
as programmed in C.
*/
#include <stdio.h> // For stdout
#include "xplatform.h" // For cross-platform xsleep() and xcls()
void goToState(void); // Prototype
// Define states (enumerated types - like ints)
@stpettersens
stpettersens / xplatform.c
Created November 19, 2010 21:33
Cross-platform functions
/*
Cross-platform header
for functions that need to work on
more than just Windows
*/
#include <stdlib.h>
#ifdef _WIN32
#include <windows.h>
#else
#include <unistd.h>