Skip to content

Instantly share code, notes, and snippets.

View tobiassjosten's full-sized avatar

Tobias Sjösten tobiassjosten

View GitHub Profile
@tobiassjosten
tobiassjosten / Dockerfile
Created December 25, 2023 17:18
Docker setup for Go app
FROM golang:1.21-alpine as compiler
ARG DOCKER_GIT_CREDENTIALS_GITHUB
ENV CGO_ENABLED=0
COPY . /tmp/src
WORKDIR /tmp/src
RUN apk --no-cache add git~=2 ca-certificates~=20230506 && \
@tobiassjosten
tobiassjosten / main.tf
Created October 1, 2023 07:12
Terraform configuration for hosting a static website with Cloud Storage and Cloudflare
terraform {
required_version = "~>1.3.6"
required_providers {
google = {
source = "hashicorp/google"
version = "~>4.84.0"
}
cloudflare = {
### Keybase proof
I hereby claim:
* I am tobiassjosten on github.
* I am tobiassjosten (https://keybase.io/tobiassjosten) on keybase.
* I have a public key whose fingerprint is 67FB 1CB5 F063 77BB 6E3D B2CC F75C 1976 31F0 8B7C
To claim this, I am signing this object:
-- http://sumedh.info/articles/importing-comments-disqus-xml-database.php
import Control.Monad
import Database.HDBC
import Database.HDBC.MySQL
main =
do conn <- connectMySQL defaultMySQLConnectInfo {
mysqlHost = "localhost",
mysqlDatabase = "tobiassjosten",
@tobiassjosten
tobiassjosten / plaguebot.py
Created February 24, 2013 17:52
My contribution to [Google AI Challenge 2010](http://planetwars.aichallenge.org/).
# -*- coding: utf8 -*-
from planetwars import BaseBot, Game
from planetwars.player import NOBODY, ME, PLAYER2, PLAYER3, PLAYER4, ENEMIES
from planetwars.universe import Universe
from planetwars.planet import Planet
from copy import copy
from logging import getLogger
import math
@tobiassjosten
tobiassjosten / phpwtf-constmember.php
Created October 15, 2012 14:45
phpwtf-constmember
<?php
class Holder
{
const myConstant = 'Stabil';
}
class Wrapper
{
public $holder;
function addition(NumbersInterface $numbers) {
// We know for sure that we can access $numbers->number1, $numbers->number2
// and $numbers->number2. This function can now do its one thing without
// being burdened with validation.
// http://en.wikipedia.org/wiki/Single_responsibility_principle
// http://en.wikipedia.org/wiki/Design_by_contract
}
interface NumbersInterface {
public $number1;
@tobiassjosten
tobiassjosten / Series.php
Created March 16, 2012 16:48
Doctrine2 m2m
<?php
namespace Smartburk\Bundle\MainBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(
* repositoryClass="Smartburk\Bundle\MainBundle\Entity\SeriesRepository"
* )
(function(_gaq) {
var path = location.pathname,
languages = ['en', 'sv'];
// We want prefix == 'en|sv|etc' or null.
var prefix = path.match(/^\/([a-z]{2})(\/.+)?$/),
prefix = prefix ? prefix[1] : null;
if (prefix && languages.indexOf(prefix) >= 0) {
// If we are on '/en|sv|etc', fallback to '/'.
# Configure colors, if available.
if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
c_reset='\[\e[0m\]'
c_user='\[\e[0;32m\]'
c_path='\[\e[1;34m\]'
c_git_clean='\[\e[0;37m\]'
c_git_staged='\[\e[0;32m\]'
c_git_unstaged='\[\e[0;31m\]'
else
c_reset=