Skip to content

Instantly share code, notes, and snippets.

Toni Suter tonisuter

Block or report user

Report or block tonisuter

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
tonisuter / gist:10a3a6b23773a459fb2b
Last active Aug 29, 2015
Refactoring Example: findMonth() function from Webkit
View gist:10a3a6b23773a459fb2b
// before refactoring
// returns 0-11 (Jan-Dec); -1 on failure
static int findMonth(const char* monthStr)
char needle[4];
for (int i = 0; i < 3; ++i) {
if (!*monthStr)
return -1;
needle[i] = static_cast<char>(toASCIILower(*monthStr++));
tonisuter / gist:8c344c6e023715902f0b
Last active Aug 29, 2015
Adding include directives using CDT
View gist:8c344c6e023715902f0b
public static void includeHeaders(HashSet<String> headers, IASTTranslationUnit ast, IDocument document) {
StringBuffer includeText = new StringBuffer();
for(String headerName : headers) {
if(!isHeaderAlreadyIncluded(headerName, ast)) {
includeText.append("\n#include <" + headerName + ">");
if(includeText.length() > 0) {
try {
tonisuter / NptTls.cpp
Last active Aug 29, 2015
Possible Refactorings
View NptTls.cpp
bool MatchDnsName(const char* hostname, const char* dns_name) {
// NULL or empty names don't match anything
if (hostname == NULL || *hostname == '\0') return false;
if (dns_name == NULL || *dns_name == '\0') return false;
// check for wildcards */
if (dns_name[0] == '*') {
// wildcard match, expect '*.' at the start, we don't match '*'
if (dns_name[1] != '.') return false;
tonisuter / gist:155f057edb3d2b4baecf
Last active Aug 29, 2015
Pipe & Stages with varying task types
View gist:155f057edb3d2b4baecf
#include <iostream>
#include <type_traits>
template<typename IN, typename OUT = IN>
struct node {
using in_type = IN;
using out_type = OUT;
template<class A, class...>
tonisuter /
Last active Aug 29, 2015
FastFlow & Liquefier



  • Type: ff_pipe
  • Header: <ff/ffpipeline.hpp>

A pipeline is a stream parallel skeleton. It has multiple stages and a task type which defines the type of the elements (tasks) that are passed from stage to stage. Each stage runs on a separate thread and works on one task at a time.

The following example shows how a pipeline with 3 stages and task type int can be created. The pipe is started

View LocationManager1.swift
let x = newHeading.x
let y = newHeading.y
let z = newHeading.z
let magnitude = sqrt(x*x + y*y + z*z)
View MotionManagerExample.swift
import UIKit
import CoreMotion
class ViewController: UIViewController {
let motionManager = CMMotionManager()
var currentAngle:Double!
override func viewDidLoad() {
View RoundedCornersDifferentRadiuses.css
View RoundedCorners.css
View Gradients.css
left top,
left bottom,
color-stop(0, rgb(255,255,255)),
color-stop(1, rgb(255,0,0))
center top,
rgb(255,255,255) 0%,
You can’t perform that action at this time.