Skip to content

Instantly share code, notes, and snippets.

// Modify contrast using a ColorMatrix (on Android)
ColorMatrixColorFilter setContrast(float contrast) {
float scale = contrast + 1.f;
float translate = (-.5f * scale + .5f) * 255.f;
float[] array = new float[] {
scale, 0, 0, 0, translate,
0, scale, 0, 0, translate,
0, 0, scale, 0, translate,
0, 0, 0, 1, 0};
ColorMatrix matrix = new ColorMatrix(array);
class ColorDict(object):
"""Provides a color for each key, trying to create as distinct a set
of colors as possible.
"""
# Minimum difference in hue between unique colors, before we begin
# to recycle old colors rather than generating new ones.
THRESHOLD = 0.05
def __init__(self):
@miracle2k
miracle2k / README
Created January 14, 2012 20:14
Optional variations in CSS
The idea is two provide optional variations for your stylesheet, for
presentation purposes, and have a switcher built into the page to
enable/disable them.
Usage - include the Javascript code in your page:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script src="cssoptions.js"></script>
Note that jQuery >= 1.7 is required.
@miracle2k
miracle2k / ServerRack.py
Created April 22, 2012 12:47 — forked from denik/ServerRack.py
class for managing multiple servers in gevent
class ServerRack(object):
"""Manages multiple gevent Servers. Works with anything that has
start() and stop() methods.
Adapted from:
https://gist.github.com/1008826
"""
def __init__(self):
self._servers = []
from webassets.test import TempEnvironmentHelper
from webassets import *
with TempEnvironmentHelper() as h:
h.create_files({
'empty': '',
'scss/styles1.scss': 'h1 { color: red }',
'scss/styles2.scss': 'h2 { color: green }',
})
@miracle2k
miracle2k / odict.py
Created July 26, 2012 20:56
Make PyYAML do very basic things.
"""Make PyYAML output an OrderedDict.
It will do so fine if you use yaml.dump(), but that generates ugly,
non-standard YAML code.
To use yaml.safe_dump(), you need the following.
"""
def represent_odict(dump, tag, mapping, flow_style=None):
"""Like BaseRepresenter.represent_mapping, but does not issue the sort().
@miracle2k
miracle2k / toast.py
Created November 17, 2012 04:45 — forked from sveetch/toast.py
Testing a bug with webassets
"""
Usage with the following directory structure : ::
sources/
js/
css/
images/
_build/
static/
css/
@miracle2k
miracle2k / TableController.js
Last active December 19, 2015 01:29
Qooxdoo Table controller.
/**
* Implement a very basic TableController.
*
* In particular, consider these limitations for now:
*
* - Only databind in one direction, from model to table.
* - When changes occur, we currently simply recreate all rows.
*
* Design-wise, one could imagine different approaches. Because the table
* is so old, it's usage is totally different from the rest of Qooxdoo. It
@miracle2k
miracle2k / plugin.js
Created August 18, 2013 13:40
CKEditor 3/4 plugin that adds a new "internal link" option to the Link dialog window. This is an adaption of Henri Medot's Drupal integration plugin (https://drupal.org/project/ckeditor_link) to a custom CMS system. I'm publishing it here because the original code includes no comments, which meant I had to figure out the CKEditor API and what th…
/**
* Add an "CMS internal link" option to the Link plugin.
*
* This was adapted from a similar plugin for Drupal (version 7.x-2.3):
* Written by Henri MEDOT <henri.medot[AT]absyx[DOT]fr>
* http://www.absyx.fr
* https://drupal.org/project/ckeditor_link
*
* Portions of code:
* Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved.
// When logged in, go to "Settings > Checkout > Checkout Language", click the "View and customize this translation" link.
// A page with a url like this opens: "https://yourshop.myshopify.com/admin/settings/locales/[locale_id]".
// copy [locale_id].
// Go Back and choose "create a new one".
// Open the Javascript console, paste this (change to your shop/locale_id first):