Skip to content

Instantly share code, notes, and snippets.

View sirupsen's full-sized avatar
🐡

Simon Eskildsen sirupsen

🐡
View GitHub Profile
@sirupsen
sirupsen / average.rb
Created August 22, 2009 20:45
Which language is best at taking all the integer paraments and get the average? Look for yourself!
def average(*numbers)
((numbers.inject {|sum, element| sum + element}) / numbers.length).to_f
end
@sirupsen
sirupsen / template.php
Created September 16, 2009 16:30
Templating abstraction in PHP.
<?php
require_once("bootstrap.php");
/*
*
* The template class to handle the output to a template file. It's good
* because it seperates all the PHP code from the actual HTML, except for
* the PHP markup used to output the data.
*
* It's used by making a file in the root directory
@sirupsen
sirupsen / template.php
Created December 2, 2009 14:30
Simple templating engine in PHP.
<?php
/*
*
* Simple template engine
*
*/
class Template {
private $data;
@sirupsen
sirupsen / tdo.rb
Created December 13, 2009 01:46
Gist for "What I Wish a Ruby Programmer Had Told Me One Year Ago".
class TodoList < Array
def self.load(file)
# read the file, create a list, create items, add them to the list, return the list
list = TodoList.new
File.read(file).each_line do |line|
list << line.chomp
end
list
end
@sirupsen
sirupsen / ws.c
Created January 22, 2010 08:03
Quine in C.
#include <stdio.h>
main() {
// String to contain program
char *program = "#include <stdio.h>%cmain() {%c char *program = %c%s%c;%c printf(program, 10, 10, 34, program, 34, 10, 10, 10);%c}%c";
/* Insert ascii characters for colon and newline
Write out the program, two new lines, at 34 we start colons
at the program pointer, in the colons write out the program
_again_ stop colons, and paste out some new lines, done! */
printf(program, 10, 10, 34, program, 34, 10, 10, 10);
}
@sirupsen
sirupsen / brainfuck.c
Created January 22, 2010 15:18
Brainfuck parser in C using seeks.
#include <stdio.h>
#include <stdlib.h>
static char *ptr;
int do_command(const char command, FILE *pFile)
{
char c;
int pos;
@sirupsen
sirupsen / launch-sakura
Created March 23, 2010 13:45
Just a single terminal. Please.
#! /bin/bash
WINTITLE="sakura" # Name of the window (or part of it)
PROGRAMNAME="sakura" # Name of the program, so it can be opened if there's no window currently
# Lists all windows, if there's one containing $WINTITLE it'll return 1, and bring the current instance of the program to the front.
if [ `wmctrl -l | grep -c "$WINTITLE"` != 0 ]
then
wmctrl -a "$WINTITLE"
# Else, it'll launch a new instance
else
@sirupsen
sirupsen / shoot.sh
Created April 20, 2010 21:31
Simple Linux screenshot utility for Imgur.
#!/bin/bash
#
# By Sirupsen @ http://sirupsen.dk
#
# Description: Very simple script to make you
# select a region of your screen, which will be captured, and
# then uploaded. The URL will then be inserted into your clipboard.
#
# Dependencies:
#
@sirupsen
sirupsen / gist:382000
Last active December 18, 2016 14:39
Template I was given by someone on #ruby to implement a simple Todo List application in Ruby many years ago.
Class TodoList
def self.load(file)
# read the file, create a list, create items, add them
end
def initialize
end
def add(item)
end
@sirupsen
sirupsen / bd.rb
Created May 15, 2010 23:23
Implementation of the "BrainDamage" language.
# Implementation of TheLinx's BrainDamage in Ruby
# => http://gist.github.com/402454
#
class BrainDamage < Array
SPACE = 32
NEWLINE = 10
def run(file)
file = get_file_content(file)