Skip to content

Instantly share code, notes, and snippets.

>>> True = False
>>> print (True and 1 == 1)
False
@wonderb0lt
wonderb0lt / gist:7601423
Last active December 29, 2015 02:38
Silly workaround for places where you can't use chsh
# At the beginning of .bashrc
zsh
exit 0
@wonderb0lt
wonderb0lt / httmock_assert.py
Created November 28, 2013 16:38
A quick fiddle with which you can assert that httmock was called in a certain way.
class httmock_assert:
def __init__(self, method=None, url=None):
self.method = method
self.url = url
self.data = None
self.headers = []
self.response = {'status_code': 200}
def assert_header(self, key, value):
self.headers.append((key, value))
<?php
$url_info = parse_url($_SERVER["REQUEST_URI"]);
$path = $url_info["path"];
header("HTTP/1.1 301 Moved Permanently");
header("Location: http://www.newwebsite.com/" . $path);
?>
@wonderb0lt
wonderb0lt / gist:7780602
Created December 4, 2013 01:03
A Go excercise for uni (word occurence counting)
package main
import (
"fmt"
"strings"
"sort"
)
type CountingResult struct {
word string
count uint
@wonderb0lt
wonderb0lt / gist:10168543
Created April 8, 2014 18:36
Average colour of a Wand Image
import colorsys
from wand.image import Image
from wand.color import Color
def get_average(image, lower_threshold=50, upper_threshold=230, sample_size=6, liveliness_boost=0.3):
"""
Calculates the average of color in the given image and gives it a bit of a "colour boost" by incrementing their hue
and saturation. This function's default are also slightly biased to prefer "lighter" colors (looks better on the
mostly white backgrounds where the images will be displayed).
@wonderb0lt
wonderb0lt / logic.py
Last active February 11, 2021 23:01
Very basic MongoEngine pagination
from math import ceil
class Pagination:
def __init__(self, items, page, per_page, total_items):
self.items = items
self.page = page
self.total_items = total_items
self.per_page = per_page
self.num_pages = int(ceil(total_items / float(per_page)))
@wonderb0lt
wonderb0lt / OverviewResource.java
Created April 15, 2014 13:11
A JAX-RS resource that shows all bound methods in the current context (RestEasy only)
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
@wonderb0lt
wonderb0lt / gist:10982332
Created April 17, 2014 13:12
I was unhappy how my Gitlab didn't look like my PyCharm, so...
// ==UserScript==
// @name Gitlab + Ubuntu + Fonts
// @namespace http://www.patrick-stegmann.de/
// @version 1.1
// @description More beautiful code display in Gitlab
// @match http://gitlab.cosee.biz/*
// @copyright 2014+, Patrick Stegmann
// ==/UserScript==
// Thanks from Google Fonts!
@wonderb0lt
wonderb0lt / gist:e0e463d50be8cc679ab7
Last active August 29, 2015 14:01
Mock requests without responses. Useful, for example, if you want to simulate non-status-code side effects like timeouts. It's a hack, but it works
class AmazonResponseMocker():
def __init__(self, response=None, timeout=False):
import requests
self.response = response
self.timeout = timeout
self.get = requests.get
def __enter__(self):
def timeout(*args, **kwargs):
from requests.exceptions import Timeout