Skip to content

Instantly share code, notes, and snippets.

View bitops's full-sized avatar

Sebastian Wittenkamp bitops

View GitHub Profile
@bitops
bitops / MediaPlayerStateWrapper.java
Created April 29, 2012 01:00 — forked from danielhawkes/MediaPlayerStateWrapper.java
A drop-in replacement for a MediaPlayer instance, that provides an accessor for the current state.
import java.io.IOException;
import java.lang.reflect.Method;
import java.util.AbstractCollection;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import android.media.AudioManager;
import android.media.MediaPlayer;
@bitops
bitops / GifView.swift
Created November 1, 2022 22:05
A SwiftUI View that renders gifs using ImageIO
import SwiftUI
import ImageIO
struct TestGif {
static let url: URL = Bundle.main.url(forResource: "your-file-here", withExtension: "gif")!
}
struct GifView: View {
@State private var gif: UIImage
@bitops
bitops / TapPhotosInCameraPickerTests.swift
Created April 12, 2022 18:08
How to tap the pre-loaded photos in the camera roll in iOS UI test
/*
LIKE: The left hand expression equals the right-hand expression: ? and * are allowed as wildcard characters, where ? matches 1 character and * matches 0 or more characters.
Resource: https://nshipster.com/nspredicate/
*/
let yellowLeafGreenBackground = NSPredicate(format: "label LIKE 'Photo, October 09, 2009, *:09*'")
let waterfallCloseUpOverRocks = NSPredicate(format: "label LIKE 'Photo, August 08, 2012, *:29*'")
let treeWithWaterfallBackground = NSPredicate(format: "label LIKE 'Photo, August 08, 2012, *:52*'")
let yellowFlowerSucculentBeach = NSPredicate(format: "label LIKE 'Photo, March 12, 2011, *:17*'")
let amazingWaterfall = NSPredicate(format: "label LIKE 'Photo, August 08, 2012, *:55*'")
@bitops
bitops / settings.json
Created December 22, 2020 08:34
VS Code setting to insert newlines at the end of files
{
"files.insertFinalNewline": true
}
@bitops
bitops / digit_sum.rb
Created January 7, 2012 05:16
Digit sum in Ruby 1.9.2
def digit_sum(n)
n.to_s.each_char.map {|c| c.to_i }.reduce(:+)
end
@bitops
bitops / BlurViewController.swift
Last active August 11, 2020 21:24
UIViewController that frosts a portion of the screen. The `toggleBlur` method is hooked up to a button on the story board.
class BlurViewController: UIViewController {
var blurView : UIVisualEffectView!
override func viewDidLoad() {
let frame = CGRect(x: view.bounds.maxX * 0.1, y: view.bounds.maxY * 0.4, width: 350, height: 200)
blurView = UIVisualEffectView(frame: frame)
blurView.effect = UIBlurEffect(style: .systemUltraThinMaterial)
view.addSubview(blurView)
}
@bitops
bitops / find_it.sh
Last active June 11, 2020 21:11
GUID regex
#!/bin/bash
grep -r -E '[a-z0-9]{8}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{12}' *
@bitops
bitops / message_region.el
Created June 27, 2012 00:28
Emacs Lisp read region into variable
;; messages the active region to the minibuffer
(defun message-region ()
(interactive)
(if (region-active-p)
(let ((region-contents-string (buffer-substring (region-beginning) (region-end))))
(message region-contents-string))
(message "Mark is not set")))
@bitops
bitops / hipchat.el
Last active November 14, 2019 20:09
HipChat + jabber.el
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; use jabber-connect to connect. Make sure you tab to select the hipchat account if it's the ;;
;; only connection configured. ;;
;; ;;
;; a fork of https://gist.github.com/puffnfresh/4002033 ;;
;; ;;
;; shout out to http://emacs.stackexchange.com/questions/10940/connecting-to-hipchat-xmpp-via-jabber-el ;;
;; for the help. ;;
;; ;;
;; you can look up the necessary jabber info on the account i
@bitops
bitops / fp-lingo.md
Created October 12, 2019 04:09 — forked from ericelliott/fp-lingo.md
A Guide to Functional Programming Lingo for JavaScripters

A Guide to Functional Programming Lingo for JavaScripters

Functional programming gets a bad wrap about being too hard for mere mortals to comprehend. This is nonsense. The concepts are actually quite simple to grasp.

The jargon is the hardest part. A lot of that vocabulary comes from a specialized field of mathematical study called category theory (with a liberal sprinkling of type theory and abstract algebra). This sounds a lot scarier than it is. You can do this!

All examples using ES6 syntax. wrap (foo) => bar means:

function wrap (foo) {