Skip to content

Instantly share code, notes, and snippets.

@berikv
berikv / gifify
Last active December 21, 2021 16:51
Transform a movie file to a gif. Specialised for demo's of Mobile app screen recordings.
#!/bin/bash
FFMPEG=$(command -v ffmpeg)
INFILE=$1
OUTFILE="${INFILE}.gif"
TMPFILE="${INFILE}_gifify_palette.png"
if ! $FFMPEG -L > /dev/null 2>&1; then
echo "Run: brew install ffmpeg"
exit 1
//
// UIColor+hex.swift
//
// Created by Berik Visschers on 05-21.
// Copyright (c) 2015 Berik Visschers. All rights reserved.
//
import UIKit
extension UIColor {
@berikv
berikv / gist:f17b6e18a8de011ec71f
Created March 27, 2015 19:46
Is user a simulator
let simulator = UIDevice.currentDevice().model.rangeOfString("Simulator") != nil
@berikv
berikv / ExponentialMovingAverage.swift
Last active December 30, 2022 18:25
Exponential Moving Average
func exponentialMovingAverage(currentAverage: Double, newValue: Double, smoothing: Double) -> Double {
return smoothing * newValue + (1 - smoothing) * currentAverage
}
// Usage:
// var a = 3
// a = exponentialMovingAverage(a, 8, 0.5)
// Swift 2
@berikv
berikv / dispatch_after_swift.codesnippet
Last active August 29, 2015 14:17
Xcode snippet for dispatch_after in Swift. Move this file to ~/Library/Developer/Xcode/UserData/CodeSnippets. Use Finder CMD+Shift+G
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDECodeSnippetCompletionPrefix</key>
<string>dispatch_after</string>
<key>IDECodeSnippetCompletionScopes</key>
<array>
<string>CodeExpression</string>
</array>
@berikv
berikv / example.txt
Created February 20, 2015 10:55
LLDB helper for printing the position of a view inside it's window
(lldb) posinwindow 0x796a0e60
(CGPoint) $58 = (x=711, y=205.5)
@berikv
berikv / log.swift
Last active August 29, 2015 14:13
Simple logging in swift
func log<T>(message: T, fileName: String = __FILE__, lineNumber: Int = __LINE__, args: CVarArgType...) {
let date = NSDate()
let processInfo = NSProcessInfo()
let appName = processInfo.processName
let combined = String(format: String(stringInterpolationSegment: message), arguments: args)
println("\(date) \(appName) [\(fileName.lastPathComponent):\(lineNumber)] \(combined)")
}
@berikv
berikv / networkActivityIndicator
Last active August 29, 2015 14:09
Multiple concurrent networkActivityIndicators
var applicationActivityIndicators = 0
extension UIApplication {
func startActivityIndicator() {
applicationActivityIndicators++
UIApplication.sharedApplication().networkActivityIndicatorVisible = true
}
func stopActivityIndicator() {
applicationActivityIndicators--
if applicationActivityIndicators <= 0 {
@berikv
berikv / gist:6765119
Last active December 24, 2015 07:39
Check iOS version
if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_6_1) {
// Load resources for iOS 6.1 or earlier
} else {
// Load resources for iOS 7 or later
}
// But only in XCode 5
@berikv
berikv / heading.py
Last active May 6, 2018 21:24 — forked from timtrueman/heading.py
- Fix wrap to allow for bigger angles - Replace the hardcoded declination correction with an argument
def wrap(angle):
while angle > 2 * pi:
angle -= 2 * pi
while angle < 0:
angle += 2 * pi
return angle
def magnetometer_readings_to_tilt_compensated_heading(bx, by, bz, phi, theta, declinationRadians=0):
""" Takes in raw magnetometer values, pitch and roll and turns it into a tilt-compensated heading value ranging from -pi to pi (everything in this function should be in radians).
The correct value for declinationRadians can be found online: http://magnetic-declination.com/countries.php note that this value is in radians, not in degrees.