Skip to content

Instantly share code, notes, and snippets.

View raek's full-sized avatar

Rasmus Bondesson raek

View GitHub Profile
class Foo(object):
def __init__(self, a_value):
self._a = None # Create private instance variable: _a
self.set_a(a_value) # Re-use the setter method so do validation and set the actual value
def get_a(self):
return self._a
def set_a(self, new_value):
class Foo(object):
def __init__(self, a_value):
self.a = a_value # Create public instance variable and assign it
f = Foo(123)
print(f.a)
f.a = 1
print(f.a)
f.a = -1
class Foo(object):
def __init__(self, a_value):
self._a = None # Create private instance variable: _a
self.a = a_value # Re-use the setter method (in the form of a property) to do validation and set the actual value
@property
def a(self): # used to be called "get_a"
return self._a
@raek
raek / Button.qml
Created January 4, 2015 22:58
Bouncy buttons in Qt Quick / QML
import QtQuick 2.0
Rectangle {
id: button
width: 75
height: 50
radius: 10
border.width: 2
border.color: Qt.darker(color, 3)
@raek
raek / calcutta2.c
Last active August 29, 2015 14:14
Rewriting whitespace
void error(const char *msg, const char *file, int line)
{
fprintf(stderr, "%s:%d: %s\n", file, line, msg);
exit(1);
}
enum keyword_ {
kw_up,
kw_down,
kw_left,
@raek
raek / Capture.hs
Last active August 29, 2015 14:15
data Exp = Lit Integer
| Add Exp Exp
| Sub Exp Exp
| Mul Exp Exp
| Neg Exp
| Abs Exp
| Sgn Exp
| Var Var
deriving Show
module Main where
import Control.Monad (mapM_)
import Control.Monad.Trans.Resource (runResourceT)
import Data.Conduit
import Data.Conduit.Attoparsec (conduitParser)
import Data.Conduit.Binary (sourceFile)
import qualified Data.Conduit.List as CL
import System.Environment (getArgs)
@raek
raek / Regex.hs
Last active August 29, 2015 14:17
module Lexis.Regex where
import Data.Char (ord)
import Data.Foldable (asum)
import Data.SciRatio.Read (readHexP, readIntegerP, readOctP, readSciRationalP)
import Data.Traversable (sequenceA)
import Data.Tuple (swap)
import Text.ParserCombinators.ReadP (ReadP, readP_to_S)
import Text.Regex.Applicative
@raek
raek / lister.py
Created March 26, 2015 22:57
List all of Bartosz Milewski's blog posts
# Run with python2
#
# Dependencies:
# pip install requests beautifulsoup4
import requests
import bs4
def main():
print "<!doctype html>".encode("utf-8")
@raek
raek / calcutta.c
Created April 7, 2015 10:52
"BombAi" programming contest example client in C
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#define ERROR(msg) error(msg, __FILE__, __LINE__)
#define FAIL() error(__FUNCTION__, __FILE__, __LINE__)
#define ASSERT(expr) do { if (!(expr)) { error(#expr, __FILE__, __LINE__); } } while (0)
void error(const char *msg, const char *file, int line)