Skip to content

Instantly share code, notes, and snippets.

Benedikt Terhechte terhechte

Block or report user

Report or block terhechte

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
@terhechte
terhechte / count_loc.py
Created Jul 9, 2019
Unobtrusive Project Language Distribution
View count_loc.py
# Usage:
# python ./count_loc.py [code-repository-folder]
# example:
# python ./count_loc.py ~/Development/our_code/
# Will count the number of files as well as the total lines
# of code in your project for different types (cpp, m, h, swift)
# and print out a json blob with the answers.
import os, sys, json
@terhechte
terhechte / benchmark.swift
Created Oct 12, 2018
Swift implementation of benchmark
View benchmark.swift
import Cocoa
func resize(image: [Int], width: Int, scale: Int) -> [Int] {
var result = [Int]()
result.reserveCapacity(image.count / scale)
for i in stride(from: 0, to: image.count, by: width) {
for i2 in stride(from: i, to: (i + width), by: scale) {
var sum = 0
for i3 in i2..<(i2 + scale) {
sum += image[i3]
@terhechte
terhechte / gist:1b7a4b1c4bc1eaa5826014379ad79c4c
Created Oct 12, 2018
C Implementation of benchmark test
View gist:1b7a4b1c4bc1eaa5826014379ad79c4c
#include <stdlib.h>
#include <stdio.h>
// We're using int64_t as `usize` and `Int` in Rust / Swift also have 8byte
int64_t* resize_image(int64_t* image, int64_t size, int64_t width, int64_t scale, int64_t* rsize) {
int64_t *result = malloc(sizeof(int64_t) * (size / scale));
int64_t pos = 0;
for (int64_t i=0; i<size; i+=width) {
for (int64_t i2=i; i2<(i + width); i2+=scale) {
View swift_process_env_example.swift
func runCocoaPods() {
DispatchQueue.global(qos: .userInitiated).async {
let process = Process()
// The trick is launching a proper login shell that hosts the task in question
// so that the environment is being initialized correctly
// `-l` forces a login shell
// `-c` tells bash to run a specific command automatically
process.launchPath = "/bin/bash"
process.currentDirectoryPath = "/Users/terhechte/Dev/tmp/testRunCocoaPods"
process.arguments = [
View gist:aabd8cba41c23047477acb1047a488c8
pragma solidity ^0.4.0;
contract ContentCreatorScore {
address public owner = msg.sender;
struct Review { string journalistId;
string correctness;
string freeText;
string depth;
string url;
}
@terhechte
terhechte / sh
Created Aug 11, 2017
Kill sourcekit if it consumes more than N amount of memory
View sh
#!/bin/bash
while true; do
fields=`ps aux -m | head | grep -i sourcekitd | tr -s ' '`
mem=`echo $fields | cut -d ' ' -s -f 6| awk '{$1=$1/1024; print $1;}' | cut -d '.' -f 1`
pid=`echo $fields | cut -d ' ' -s -f 2`
# how much mem before we're killing it. default 5000
if [ "$mem" -gt 5000 ]; then
echo "Killing sourcekitservice pid $pid with mem $mem"
kill -9 $pid
sleep 5
@terhechte
terhechte / xcode-filler.sh
Created Oct 23, 2016
Fill Xcode Product with unused space so the app looks bigger than it is
View xcode-filler.sh
# What crazy talk is this?
# See: https://twitter.com/myell0w/status/790245699694854145
#
# In a world where everything has to be bigger, faster, higher and more,
# users seem to have developed the expectation that the bigger the software
# package, the better the software. However, if you fill up your binary with
# useless data, the app store size might be too high and your app will
# require download over wifi.
#
# The following script can be added to your Xcode target as a shell script.
View gist:e32587b783c3b8ef5fb8
print("Swiftstub Running XCode 7.1 Swift 2")
typealias Item = String
enum ObserverAction {
case Update(items: [Item])
case Delete(items: [Item])
case Insert(items: [Item])
}
View keybase.md

Keybase proof

I hereby claim:

  • I am terhechte on github.
  • I am terhechte (https://keybase.io/terhechte) on keybase.
  • I have a public key whose fingerprint is 9637 08F2 4838 F953 6D90 FA3F 7CD9 6B05 258B 7980

To claim this, I am signing this object:

@terhechte
terhechte / gtk3-swift-package-issues.scala
Last active Jan 23, 2016
GTK3 Linux Swift header issues
View gtk3-swift-package-issues.scala
/**
I tried to get GTK running with Swift. To run this, a Linux machine with a working GTK3
installation is needed (could also work with OSX && brew install gtk+3, however I did not try that);
i.e.
`sudo apt-get install libgtk-3-dev`
Initially I tried with GTK but since GTK has dependencies to a lot of other things, I tried something
simpler, i.e. in this case GDK which has only dependencies to X11.
You can’t perform that action at this time.