Skip to content

Instantly share code, notes, and snippets.

@reitzig
reitzig / sebibtex.tex
Last active September 17, 2015 13:43
A small MWE for testing SE BibTeX export with biblatex+biber vs bibtex+natbib
\documentclass{article}
\def\testmode{old}
\def\testmode{new}
\usepackage{xifthen,url}
\newcommand{\ifnew}[2]{\ifthenelse{\equal{\testmode}{new}}{#1}{#2}}
\ifnew{%
\usepackage[backend=biber]{biblatex}
@reitzig
reitzig / math4slack.js
Created November 17, 2015 10:27
MathJax for Slack -- Attempt 1
( function () { // start of anonymous wrapper function (needed to restrict variable scope on Opera)
// Opera does not support @match, so re-check that we're on SE chat before doing anything
// if ( location.hostname != 'slack.com' ) return;
// Baseline MathJax URL and config, copied from SE:
var mathJaxURL = "//cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML-full";
var config = {
"HTML-CSS": { preferredFont: "TeX", availableFonts: ["STIX","TeX"], linebreaks: { automatic:true }, EqnChunk: 50 },
tex2jax: { inlineMath: [ ["$", "$"], ["\\\\(","\\\\)"] ], displayMath: [ ["$$","$$"], ["\\[", "\\]"] ], processEscapes: true, ignoreClass: "tex2jax_ignore|dno" },
@reitzig
reitzig / def-comments-csSE.json
Last active September 4, 2018 05:16
Default comments for cs.SE for remote use with AutoReviewComments. They reflect the ones available at meta.cs.stackexchange.com/q/627
callback([
{ "name": "[Q] Problem dump",
"description": "We discourage posts that simply state a problem out of context, and expect the community to solve it. Assuming you tried to solve it yourself and got stuck, it may be helpful if you wrote your thoughts and what you could not figure out. It will definitely draw more answers to your post. Until then, the question will be voted to be closed / downvoted. You may also want to check out [these hints](http://meta.cs.stackexchange.com/q/1284/98), or use the search engine of this site to find similar questions that were already answered."
},
{ "name": "[Q] No effort shown, no specific question",
"description": "What have you tried? Where did you get stuck? We do not want to just hand you the solution; we want you to gain understanding. However, as it is we do not know what your underlying problem is, so we can not begin to help. See [here](http://meta.cs.stackexchange.com/q/1284/98) for tips on asking questions about exercise problems. If you are uncertain
@reitzig
reitzig / btTraverse.scala
Last active February 26, 2016 15:15
In-order binary tree traversal in Scala
object Main extends App {
def foreach[B, A >: B](f : A => Unit)(tree : BT[B]) {
tree match {
case Leaf(v) => f(v)
case Inner(v,l,r) => {
foreach(f)()lgis
f(v)
foreach(f)(r)
}
}
@reitzig
reitzig / weighted_rank.scala
Created March 10, 2016 15:27
Weighted ranking of athletes
// cf http://cs.stackexchange.com/q/54253/98
// Runnable version: http://ideone.com/4GyKeB
class Athlete(val name: String, val endurance : Int, val speed : Int) {
def performance(p : Double) = {
p * endurance / Athlete.maxEndurance + (1-p) * speed / Athlete.maxSpeed
}
override def toString = name
}
@reitzig
reitzig / CwlCountdownLatch.swift
Last active February 28, 2017 07:40
A countdown latch based ob CwlUtils primitives
//
// CwlCountdownLatch.swift
// CwlUtils
//
// Created by Raphael Reitzig on 2017/02/16.
// Copyright © 2017 Raphael Reitzig. All rights reserved.
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
@reitzig
reitzig / ConstructorMagic.swift
Last active March 1, 2017 10:47
Constructing new values in a public function using initializers from an internal protocol
// Using Swift 3.0.1
// see also http://stackoverflow.com/q/42514600/539599
import Foundation
public protocol P {
var foo: Int { get }
}
internal protocol Q {
@reitzig
reitzig / Data.swift
Last active April 15, 2022 03:47
Reading InputStream into Data
extension Data {
/**
Consumes the specified input stream, creating a new Data object
with its content.
- Parameter reading: The input stream to read data from.
- Note: Closes the specified stream.
*/
init(reading input: InputStream) {
self.init()
input.open()
@reitzig
reitzig / StringCutter.swift
Last active April 7, 2017 12:54
String prefix and suffix for Swift 3.0
import Foundation
extension String {
/**
Drops characters from the front and the end of this string, returning
what remains.
- Parameter first: The number of characters to drop from the beginning.
Values smaller than 0 are treated as 0.
- Parameter last: The number of characters to drop from the end.
@reitzig
reitzig / convert.rb
Created April 15, 2017 09:05
Default comments for cs.SE for import into AutoReviewComments. Obtained from https://gist.github.com/reitzig/7ca05408f53292505294 using the script attached below.
#!/usr/bin/ruby
require 'json'
# Note: remove `callback(` and the matching `)` from the jsonp file; it should only contain a JSON array.
File.open(ARGV[0]) { |f|
comments = JSON.parse(f.read)
puts comments.map { |c|
"####{c["name"]}\n#{c["description"]}\n\n"
}