Skip to content

Instantly share code, notes, and snippets.

@Novum
Novum / gist:1200562
Created September 7, 2011 13:31
Fast SSE pow for range [0, 1]
// Fast SSE pow for range [0, 1]
// Adapted from C. Schlick with one more iteration each for exp(x) and ln(x)
// 8 muls, 5 adds, 1 rcp
inline __m128 _mm_fastpow_0_1_ps(__m128 x, __m128 y)
{
static const __m128 fourOne = _mm_set1_ps(1.0f);
static const __m128 fourHalf = _mm_set1_ps(0.5f);
__m128 a = _mm_sub_ps(fourOne, y);
__m128 b = _mm_sub_ps(x, fourOne);
@mikemilano
mikemilano / gist:6923819
Last active September 18, 2016 03:43
Python's Twisted framework watching a directory and broadcasting changes to zeromq.
from twisted.internet import inotify
from twisted.python import filepath
import zmq
from pprint import pprint
class FileSystemWatcher(object):
def __init__(self, path_to_watch):
self.path = path_to_watch
self.context = zmq.Context()
@dwilliamson
dwilliamson / Triangle.cpp
Created August 22, 2014 13:26
Dumb but accurate triangle rasteriser with top-left fill
void RasteriseTriangle3(char* buffer, int width, int height, float2 v0, float2 v1, float2 v2)
{
// Sort vertices along the y-axis, lowest first
if (v1.y < v0.y)
std::swap(v0, v1);
if (v2.y < v1.y)
std::swap(v1, v2);
if (v1.y < v0.y)
std::swap(v0, v1);
@shanechin
shanechin / gist:2424076
Created April 19, 2012 20:49
Computer Modern Fonts
<style type="text/css">
@font-face {
font-family: "Computer Modern";
src: url('http://mirrors.ctan.org/fonts/cm-unicode/fonts/otf/cmunss.otf');
}
@font-face {
font-family: "Computer Modern";
src: url('http://mirrors.ctan.org/fonts/cm-unicode/fonts/otf/cmunsx.otf');
font-weight: bold;
}
@sphaero
sphaero / dyn_dns_app.py
Last active April 6, 2020 16:04
Simple DynDNS Service using (apache) webserver and DNSMasq
#!/usr/bin/env python
# Simple Dynamic DNS update script for use with DNSMasq
#
# Install this WSGI script on a (apache) webserver. Make sure
# DNSMasq runs as the same user as this script does on the webserver
# E.g: /etc/default/dnsmasq add: (Debian and deriatives)
# DNSMASQ_USER='wsgiuser'
#
# ### DNSMASQ.CONF ###
# domain-needed
@gleicon
gleicon / txsyslogd.py
Created December 21, 2010 12:14
minimalistic syslog daemon written with twisted.
#!/usr/bin/python
# -*- coding: utf-8 -*-
# launchctl unload /System/Library/LaunchDaemons/com.apple.syslogd.plist
# launchctl load /System/Library/LaunchDaemons/com.apple.syslogd.plist
from twisted.internet import reactor, stdio, defer
from twisted.internet.protocol import Protocol, Factory
from twisted.protocols.basic import LineReceiver
import time, re, math, json
"""
twisted async/await with asyncio reactor and uvloop
"""
import asyncio
import uvloop
from asyncio.tasks import ensure_future
try:
# as per github source the asyncio reactor is intended to be released in future version
@rygorous
rygorous / Stats.js
Created April 25, 2012 03:48
Half-space tri rasterizers in JS
// stats.js r9 - http://github.com/mrdoob/stats.js
var Stats=function(){var h,a,r=0,s=0,i=Date.now(),u=i,t=i,l=0,n=1E3,o=0,e,j,f,b=[[16,16,48],[0,255,255]],m=0,p=1E3,q=0,d,k,g,c=[[16,48,16],[0,255,0]];h=document.createElement("div");h.style.cursor="pointer";h.style.width="80px";h.style.opacity="0.9";h.style.zIndex="10001";h.addEventListener("mousedown",function(a){a.preventDefault();r=(r+1)%2;0==r?(e.style.display="block",d.style.display="none"):(e.style.display="none",d.style.display="block")},!1);e=document.createElement("div");e.style.textAlign=
"left";e.style.lineHeight="1.2em";e.style.backgroundColor="rgb("+Math.floor(b[0][0]/2)+","+Math.floor(b[0][1]/2)+","+Math.floor(b[0][2]/2)+")";e.style.padding="0 0 3px 3px";h.appendChild(e);j=document.createElement("div");j.style.fontFamily="Helvetica, Arial, sans-serif";j.style.fontSize="9px";j.style.color="rgb("+b[1][0]+","+b[1][1]+","+b[1][2]+")";j.style.fontWeight="bold";j.innerHTML="FPS";e.appendChild(j);f=document.createElement("div");f.style.position="relati
@donny-dont
donny-dont / aligned_allocator.cpp
Created December 13, 2011 09:11
An aligned allocator for placing SIMD types in std::vector
#ifdef _WIN32
#include <malloc.h>
#endif
#include <cstdint>
#include <vector>
#include <iostream>
/**
* Allocator for aligned data.
@rygorous
rygorous / gist:2203834
Created March 26, 2012 08:03
float->sRGB8 using SSE2 (and a table)
// float->sRGB8 conversions - two variants.
// by Fabian "ryg" Giesen
//
// I hereby place this code in the public domain.
//
// Both variants come with absolute error bounds and a reversibility and monotonicity
// guarantee (see test driver code below). They should pass D3D10 conformance testing
// (not that you can verify this, but still). They are verified against a clean reference
// implementation provided below, and the test driver checks all floats exhaustively.
//