Skip to content

Instantly share code, notes, and snippets.

Niklas Fiekas niklasf

Block or report user

Report or block niklasf

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@niklasf
niklasf / db.class.php
Created Feb 22, 2011
A reusable class for MySQL queries in PHP.
View db.class.php
<?php
error_reporting(E_ALL);
define('DB_HOSTNAME', 'localhost');
define('DB_USERNAME', '***');
define('DB_PASSWORD', '***');
define('DB_DATABASE', '***');
define('DB_PCONNECT', TRUE);
@niklasf
niklasf / tic-tac-toe.js
Last active Dec 16, 2015
Tic-tac-toe over TCP.
View tic-tac-toe.js
var net = require('net');
var nextGame = null;
function Game() {
var self = this;
this.clients = new Array();
var board = new Array("1", "2", "3",
@niklasf
niklasf / update.py
Created May 1, 2013
Sample Git update hook that deploys the changed files to the web root.
View update.py
#!/usr/bin/python
import logging
import git
import sys
import os
def main():
"""
Update all files according to a diff.
@niklasf
niklasf / lebesgue.py
Created May 2, 2013
Calculate the lebesgue constant of a polynomial interpolation operator.
View lebesgue.py
import math
n = 20
#x_k = [-1 + 2 * k / float(n) for k in range(0, n + 1)]
x_k = [math.cos((2.0 * k + 1) / (2.0 * n +2.0) * math.pi)
for k in range(0, n + 1)]
def l_j(j, x):
@niklasf
niklasf / matrixmult.py
Last active Dec 17, 2015
An O(n^2.81) n-x-n-matrix multiplication algorithm.
View matrixmult.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import unittest
def multiply(A, B):
if len(A) == 1:
return [[ A[0][0] * B[0][0] ]]
elif len(A) % 2 == 1:
return shrink(multiply(expand(A), expand(B)))
@niklasf
niklasf / title_and_description_delegate.cpp
Last active Jan 3, 2018
A Qt QItemDelegate that shows a bold title above a description text. Could also be used to render more general rich text in QTableView and co.
View title_and_description_delegate.cpp
#include "title_and_description_delegate.h"
void TitleAndDescriptionDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
m_paintingIndex = index;
QItemDelegate::paint(painter, option, index);
}
void TitleAndDescriptionDelegate::drawDisplay(QPainter *painter, const QStyleOptionViewItem &option, const QRect &rect, const QString &text) const
{
View spi.c
/*
* GccApplication1.c
*
* Created: 19.11.2013 13:22:54
* Author: ese1-30
*/
#include <avr/io.h>
#include <util/delay.h>
View isr.c
#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h>
void display_internal(uint8_t mask, uint8_t c)
{
uint8_t bm = mask == 0x0F ? 0b00000000 : 0b00001000;
uint8_t sh = mask == 0x0F ? 0 : 4;
if ((c & mask) >> sh == 0x00) {
You can’t perform that action at this time.