Skip to content

Instantly share code, notes, and snippets.

#include <stdio.h>
class Integer
{
public:
Integer& Inc(int val) { _Value += val; return *this; }
void Print() const { printf("%d", _Value); }
void operator=(int rhs) { _Value = rhs; }
@kaedroho
kaedroho / dialogs.java
Last active October 12, 2015 06:08
Java Dialogs
/**
* Dialogs
* Some handy functions to get various types of data from a user using JoptionPane
* @author Karl Hobley
* @version r23
*/
import javax.swing.*;
import javax.swing.filechooser.*;
import java.io.File;
@kaedroho
kaedroho / sawblade.py
Last active January 1, 2016 16:29
Sawblade generator
from fractions import Fraction
import math
def circle_point(angle, diameter):
return (
math.sin(angle * math.pi * 2) * diameter,
math.cos(angle * math.pi * 2) * diameter,
)
@kaedroho
kaedroho / models.py
Last active August 29, 2015 13:57
Routing change
def route_self(self, request, path_components):
"""
Override this if you want to use custom routing
"""
if path_components:
# path_components has been set but this page doesn't use custom routing
raise Http404
else:
return self.serve(request)
@kaedroho
kaedroho / models.py
Created March 13, 2014 19:52
Wagtail SuperPage class
from django.template.response import TemplateResponse
from django.core.urlresolvers import RegexURLResolver, RegexURLPattern, Resolver404
from wagtail.wagtailcore.models import Page
class SuperPage(Page):
ajax_template = None
def get_context(self, request):
@kaedroho
kaedroho / description.py
Last active August 29, 2015 13:57
PR144 description
# This gist describes the changes I have made in PR #144
# Add AJAX template (1cb7dcb0b29bd2d20016515b922cfc9ca8de9be4)
# ============================================================
# The first of my changes is allowing ajax templates to be specified as an attribute to the page class.
# I created a method called get_template() which finds the best template to use for a particular request.
# This function is overridable so a developer can have a more advanced configuration if they want.
# If this is not filled out, the ajax template will fall back to the standard template.
# This addresses a very common pattern in the RCA source.
# Upgrade system
sudo apt-get update -y
sudo apt-get upgrade -y
# Base packages
sudo apt-get install -y git vim sqlite3 build-essential screen
sudo apt-get install -y libssl-dev libxml2-dev libxslt-dev
sudo apt-get install -y libjpeg-dev libtiff-dev zlib1g-dev libfreetype6-dev liblcms2-dev
# Python
@kaedroho
kaedroho / superpage.py
Last active September 21, 2019 01:20
from django.http import Http404
from django.core.urlresolvers import RegexURLResolver
from django.conf.urls import url
from wagtail.wagtailcore.models import Page
class SuperPage(Page):
"""
This class extends Page by adding methods to allow urlconfs to be embedded inside pages
from django.db import models
from modelcluster.fields import ParentalKey
from wagtail.wagtailcore.models import Page, Orderable
from wagtail.wagtailadmin.edit_handlers import FieldPanel, InlinePanel
class Thing(models.Model):
...
# Update apt
sudo apt-get update -y
# Install base packages
sudo apt-get install vim git build-essential sqlite3 screen -y
# Git config
git config --global user.name "Karl Hobley"
git config --global user.email karlhobley10@gmail.com