Skip to content

Instantly share code, notes, and snippets.

View halfdan's full-sized avatar
🇩🇪

Fabian Becker halfdan

🇩🇪
View GitHub Profile
@halfdan
halfdan / post.rb
Created September 12, 2012 21:35
Taggable Post model in Rails 3.2.x
class Post < ActiveRecord::Base
attr_accessible :body, :title, :tag_names
attr_reader :tag_names
has_many :taggings
has_many :tags, :through => :taggings
def tag_names=(tag_list)
tag_names = tag_list.gsub(/\s+/, "").split(",")
existing = self.tags.map {|t| t.name }
@halfdan
halfdan / YinYangPanel.java
Created May 24, 2012 12:50
YinYangPanel, a JPanel that draw a YinYang symbol
package eu.geekproject;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Graphics;
import javax.swing.JFrame;
import javax.swing.JPanel;
/**
* Basic JPanel that draws a YinYang symbol.
static void generateCodeCallStmt(Absyn *node, Table *table, Entry *currentMethod,
int returnLabel, int breakLabel) {
Absyn *rcvr = node->u.callStm.rcvr;
Absyn *args = node->u.callStm.args;
Sym *name = node->u.callStm.name;
Class *rcvrClass = node->u.callStm.rcvrClass;
Class *rcvrMetaClass = rcvrClass->metaClass;
Entry *methodEntry;
int offset;
int numParams;
@halfdan
halfdan / gist:1925936
Created February 27, 2012 18:16
Simple Ninja class
public class Main extends Object {
public static void main() {
local Integer x;
local Integer y;
x = 42.add(23);
y = 42.add(23);
System.writeInteger(x);
System.writeInteger(y);
}
}
/*
* semant.c -- semantic analysis
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
@halfdan
halfdan / gist:1514831
Created December 23, 2011 17:21
Ninja Compiler - translation into tree language
// Programm
void f(boolean b) {
local integer a1;
local integer a2;
if (b) {
a1 = 2;
a2 = 22;
} else {
a1 = 3;
@halfdan
halfdan / gist:1435768
Created December 5, 2011 22:48
36cities unordered numbers for Travelling Salesman GA
18 2 23 4 25 6 7 21 9 34
36 0 0 0 0 0 0 0 0 16
35 0 0 0 0 0 0 0 0 12
10 0 0 0 0 0 0 0 0 27
33 0 0 0 0 0 0 0 0 14
15 0 0 0 0 0 0 0 0 32
31 0 0 0 0 0 0 0 0 11
30 0 0 0 0 0 0 0 0 17
19 0 0 0 0 0 0 0 0 1
28 13 26 3 24 5 22 8 20 29
// Generate random genes
ts.genes = make([]ga.Gene, ts.nGenes)
var proto = make([]int, ts.geneLength)
var i int = 0
for key, _ := range coords {
proto[i] = key
i++
}
// Initialize all len(genes) and shuffle
@halfdan
halfdan / bool_test.c
Created May 27, 2011 20:46
Bool in C99
#include <stdbool.h>
#include <stdio.h>
bool test = false;
int main(void) {
if(test) {
printf("Test is true");
}
else {
@halfdan
halfdan / 201102032216_create_users.php
Created February 3, 2011 21:16
ActiveRecord\Migration - CreateTable
<?php
class CreateUsers extends ActiveRecord\Migration {
public function up() {
$this->create_table('users', array(
// <field> => array(<type>, <length>, <nullable>)
'name' => array('varchar', 12, FALSE),
'email' => array('varchar', 255, FALSE)
));