Skip to content

Instantly share code, notes, and snippets.

@pebreo
pebreo / gist:5234142
Created March 24, 2013 23:57
Qt code for looping throgh QTextDocument
QStringList images;
QTextBlock b = document->begin();
while (b.isValid()) {
for (QTextBlock::iterator i = b.begin(); !i.atEnd(); ++i) {
QTextCharFormat format = i.fragment().charFormat();
bool isImage = format.isImageFormat()
if (isImage)
images << format.toImageFormat().name();
}
b = b.next();
@pebreo
pebreo / ngram.py
Last active July 28, 2018 21:02
An n-gram generator in Python (newbie program)
from collections import Counter
from random import choice
import re
class Cup:
""" A class defining a cup that will hold the words that we will pull out """
def __init__(self):
self.next_word = Counter() # will keep track of how many times a word appears in a cup
import requests
class HoverException(Exception):
pass
class HoverAPI(object):
def __init__(self, username, password):
params = {"username": username, "password": password}
r = requests.post("https://www.hover.com/signin", params=params)
@pebreo
pebreo / chess.coffee
Last active December 25, 2015 03:49
Coffeescript Chess (via KhanAcademy) https://www.khanacademy.org/cs/new-program/2193445389
#Thanks for all the votes, I never expected that much, just 1 or 2.
noCursor()
frameRate 20000000000000000000000000000
colors = []
board = [2000000000000000, " RNBQKBNR", " PPPPPPPP", " ........", " ........", " ........", " ........", " PPPPPPPP", " RNBQKBNR"]
sides = [0, " bbbbbbbb", " bbbbbbbb", " ........", " ........", " ........", " ........", " wwwwwwww", " wwwwwwww"]
possibleMoves = [0, " 00000000", " 00000000", " 00000000", " 00000000", " 00000000", " 00000000", " 00000000", " 00000000"]
#var board = [0,
#" RNBQKBNR",
@pebreo
pebreo / planets-wander.coffee
Created October 12, 2013 00:20
Why Planets Wander (in Coffescript via js2coffee.org) original source: Khan Academy: https://www.khanacademy.org/cs/spin-off-of-why-planets-wander/2207805122
#
# * Simulation of telescope on Earth looking at the night
# * sky (ignoring the rotation of the Earth).
# *
# * Telescope angles relative to vernal equinox (First Point of Aries).
# *
# * - Planets -
# * Green: Mercury
# * Gray: Venus
# * Brown: Mars
@pebreo
pebreo / excel_py_tokenize.py
Created October 19, 2013 05:08
Tokenize Excel formula
#========================================================================
# Description: Tokenise an Excel formula using an implementation of
# E. W. Bachtal's algorithm, found here:
#
# http://ewbi.blogs.com/develops/2004/12/excel_formula_p.html
#
# Tested with Python v2.5 (win32)
# Author: Robin Macharg
# Copyright: Algorithm (c) E. W. Bachtal, this implementation (c) R. Macharg
#
@pebreo
pebreo / uibtre.py
Last active December 27, 2015 19:59
Remote Tank Control using Android SL4A + Bluetooth
# Video of the code in action: http://www.youtube.com/watch?v=BtmRBxRsMk4
#! python
# -= encoding=utf-8 =-
##############################################################################
#
# uibtre.py $Rev:$
# $Id$
#
# Copyright (c) 2011, shimoda as kuri65536 _dot_ hot mail _dot_ com
# ( email address: convert _dot_ to . and joint string )
@pebreo
pebreo / jquery-html-skeleton.html
Last active December 29, 2015 21:09
jQuery + HTML skeleton
<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
<script type="text/javascript">
$(function() {
$('#mybutton').click(function() {
});
@pebreo
pebreo / django-jquery-demo.py
Last active April 29, 2020 05:15
jQuery AJAX + Django SIMPLE DEMO
# views.py - django app called ajx
from django.shortcuts import render, get_object_or_404, redirect, HttpResponse, render_to_response, HttpResponseRedirect
from django.core.urlresolvers import reverse
from django.contrib.auth import authenticate, login
import json
def mygetview(request):
if request.method == 'GET':
@pebreo
pebreo / basic-column-highcharts.html
Created December 1, 2013 21:34
jsFiddle for HighChart basic column
<!-- Use jQuery 1.9.1 -->
<script src="http://code.highcharts.com/highcharts.js"></script>
<script src="http://code.highcharts.com/modules/exporting.js"></script>
<div id="container" style="min-width: 310px; height: 400px; margin: 0 auto"></div>
<!-- javascript -->
$(function () {
var chart = {