Skip to content

Instantly share code, notes, and snippets.

View stpettersens's full-sized avatar

Sam Saint-Pettersen stpettersens

View GitHub Profile
@stpettersens
stpettersens / method_missing_demo.rb
Created July 19, 2011 11:28
Method Missing Demo
module MyModule
# Public methods.....
def self.doSomething(parameter)
...
end
def self.doSomethingElse()
...
end
@stpettersens
stpettersens / gist:726292
Created December 2, 2010 23:10
Why not incrementing z?
while(1) {
strcpy(fsm.state[x][z], lines[i]);
printf("%i %i\n", x, z);
z++; i++;
if(strcmp(lines[i], ".") == 0) x++; z = 0;
if(strcmp(lines[i], "") == 0) break;
}
@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>
@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 / 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()
}
}
sPerson.scala:
class sPerson extends jPerson {
def getName(): String = "Sammy Saint"
}
jPerson.java:
public interface jPerson {
public String getName();
/*
Groovy class inheritence demonstration
*/
class Ancestor {
def name
Ancestor() {
name = "Homo erectus"
}
def speak() {
println "I am " + name
// 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;
}
#!/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
/*
Hello World in Scala
*/
object HelloWorld {
def main(args: Array[String]) {
println("Hello World!")
}
}
- OR -