Skip to content

Instantly share code, notes, and snippets.

View bjorn's full-sized avatar
🇳🇱

Thorbjørn Lindeijer bjorn

🇳🇱
View GitHub Profile
@bjorn
bjorn / gist:11011338
Created April 17, 2014 21:00
Keybase proof
### Keybase proof
I hereby claim:
* I am bjorn on github.
* I am bjorn (https://keybase.io/bjorn) on keybase.
* I have a public key whose fingerprint is F0F4 30DC 9685 89CA C31D 17B4 10B2 90EF C9F1 1EB9
To claim this, I am signing this object:
@bjorn
bjorn / object.lua
Created December 15, 2011 18:32
Lua OOP system
--
-- Object is the base class of anything that follows this OOP mechanism.
-- Usage example:
--
--
-- CREATING A DERIVED CLASS
--
-- local Human = Object:subclass {
-- name = "Anonymous",
-- weight = 0,
@bjorn
bjorn / createupdates.lua
Created July 14, 2012 21:01
Scripts around manaserv
#!/usr/bin/env lua
local function checkenv(varname)
local value = os.getenv(varname)
if not value then
print(varname .. ' not set')
os.exit(1)
end
return value
end
@bjorn
bjorn / durationlogger.h
Created August 17, 2012 17:47
Duration Logger (Qt)
#ifndef DURATIONLOGGER_H
#define DURATIONLOGGER_H
#include <QTime>
/**
* A helper class that logs the duration of a specific scope.
*/
class DurationLogger
{
@bjorn
bjorn / authors.rb
Created August 23, 2012 20:47
Generate copyright header author lists
#!/usr/bin/env ruby
# This script can be used to generate a list of authors for each source file,
# for inclusion in the copyright header.
require 'rugged'
require 'set'
repo = Rugged::Repository.new(".")
@bjorn
bjorn / delete-container
Last active December 17, 2015 00:19
libcloud based scripts
#!/usr/bin/env python2
#
# Warning: this script will delete the given container, including its contents
#
from argparse import ArgumentParser
from os import environ
from sys import exit
from libcloud.storage.types import Provider, ContainerDoesNotExistError
@bjorn
bjorn / FlexibleScrollBar.cpp
Created December 21, 2015 11:19
A flexible QScrollBar that can take values outside of its original range by automatically extending its range
class FlexibleScrollBar : public QScrollBar
{
Q_OBJECT
public:
FlexibleScrollBar(Qt::Orientation orientation, QWidget *parent = nullptr)
: QScrollBar(orientation, parent)
, mOverrideMinimum(0)
, mOverrideMaximum(0)
, mDesiredMinimum(0)
@bjorn
bjorn / benchmark.lua
Created December 14, 2011 10:57
Lua OOP benchmark
-- This benchmark compares two ways of creating objects.
-- Output commonly seen on the Lua demo site:
--
-- Creation time: 0.16
-- Calling member function time: 0.11
-- Memory: 2868.8798828125
--
-- Creation time: 0.11
-- Calling member function time: 0.13
-- Memory: 1697.4736328125
@bjorn
bjorn / FrameTabBarBase.cpp
Last active September 12, 2016 12:37
Drawing tab bar base behind some other control
QStylePainter p(this);
QStyleOptionTab tabOverlap;
int overlap = style()->pixelMetric(QStyle::PM_TabBarBaseOverlap, &tabOverlap);
QStyleOptionTabBarBase tabBarStyleOption;
tabBarStyleOption.rect.setRect(0, height() - overlap, width(), overlap);
tabBarStyleOption.tabBarRect = rect();
p.drawPrimitive(QStyle::PE_FrameTabBarBase, tabBarStyleOption);
@bjorn
bjorn / dds2image.cpp
Last active September 12, 2016 12:40
Loading a DDS to a QImage using QGLPixelBuffer.
QImage readDDSFile(const QString &filename)
{
QGLWidget glWidget;
glWidget.makeCurrent();
GLuint texture = glWidget.bindTexture(filename);
if (!texture)
return QImage();
// Determine the size of the DDS image