Skip to content

Instantly share code, notes, and snippets.

View michaelevensen's full-sized avatar

Michael Nino Evensen michaelevensen

View GitHub Profile
@dergachev
dergachev / GIF-Screencast-OSX.md
Last active July 17, 2024 14:20
OS X Screencast to animated GIF

OS X Screencast to animated GIF

This gist shows how to create a GIF screencast using only free OS X tools: QuickTime, ffmpeg, and gifsicle.

Screencapture GIF

Instructions

To capture the video (filesize: 19MB), using the free "QuickTime Player" application:

@vigorouscoding
vigorouscoding / DateFlowLayout.h
Created March 13, 2013 20:10
UICollectionView with sticky headers which works for horizontal as well as vertical scrolling
#import <UIKit/UIKit.h>
@interface DateFlowLayout : UICollectionViewFlowLayout
@end
//
// ViewController.m
// AVPlayerCaching
//
// Created by Anurag Mishra on 5/19/14.
// Sample code to demonstrate how to cache a remote audio file while streaming it with AVPlayer
//
#import "ViewController.h"
#import <AVFoundation/AVFoundation.h>
@sararob
sararob / data-structure.js
Last active April 26, 2022 22:21
Role-based security in Firebase
/*
This example shows how you can use your data structure as a basis for
your Firebase security rules to implement role-based security. We store
each user by their Twitter uid, and use the following simplistic approach
for user roles:
0 - GUEST
10 - USER
20 - MODERATOR
@ryanhanwu
ryanhanwu / mapViewController.m
Last active November 4, 2022 11:43
Calculate Google Map length in meters with zoom level in #Objective-C (converted from #JavaScript) #iOS #Swift
- (void)mapView:(GMSMapView*)mapView idleAtCameraPosition:(GMSCameraPosition*)position
{
CLLocationCoordinate2D topLeft = mapView.projection.visibleRegion.farLeft;
CLLocationCoordinate2D bottomLeft = mapView.projection.visibleRegion.nearLeft;
double lat = fabs(topLeft.latitude - bottomLeft.latitude);
double mpp = cos(lat * M_PI / 180) * 2 * M_PI * 6378137 / (256 * pow(2, mapView.camera.zoom));
double distance = mpp * mapView.frame.size.width;
[[SearchManager shareInstance] distance: distance];
}
@AliSoftware
AliSoftware / struct_vs_inheritance.swift
Last active March 27, 2024 11:57
Swift, Struct & Inheritance: How to balance the will of using Struct & Value Types and the need for Inheritance?
// #!Swift-1.1
import Foundation
// MARK: - (1) classes
// Solution 1:
// - Use classes instead of struct
// Issue: Violate the concept of moving model to the value layer
// http://realm.io/news/andy-matuschak-controlling-complexity/
@Koze
Koze / PhotosScreenshot.m
Last active November 30, 2022 22:12
Getting All Screenshots with Photos.framework
NSMutableArray *mArray = [NSMutableArray array];
// fetch all image assets
PHFetchOptions *fetchOptions = [[PHFetchOptions alloc] init];
fetchOptions.predicate = [NSPredicate predicateWithFormat:@"mediaType == %d", PHAssetMediaTypeImage];
PHFetchResult *result = [PHAsset fetchAssetsWithOptions:fetchOptions];
[result enumerateObjectsUsingBlock:^(PHAsset * __nonnull asset, NSUInteger idx, BOOL * __nonnull stop) {
// filter with subtype for screenshot
if (asset.mediaSubtypes & PHAssetMediaSubtypePhotoScreenshot) {
[mArray addObject:asset];
@rajohns08
rajohns08 / BorderButton.swift
Last active November 14, 2017 09:00
iOS / Swift - IBDesignable and IBInspectable working example for a UIButton subclass with a border
import UIKit
@IBDesignable
class BorderButton: UIButton {
@IBInspectable var cornerRadius: CGFloat = 0 {
didSet {
layer.cornerRadius = cornerRadius
layer.masksToBounds = cornerRadius > 0
}
@seivan
seivan / filter.swift
Created January 16, 2016 01:21
Sample CIFilter with Swift.
@objc class JPTiltShiftGenerator: NSObject, CIFilterConstructor {
@objc func filterWithName(name: String)->CIFilter? {
return JPTiltShift()
}
}
class JPTiltShift : CIFilter {
class func register() {
@skreutzberger
skreutzberger / relativeDateInterval.swift
Last active April 17, 2023 12:32
Swift 2 function for human-readable time interval
/// returns optional relative date interval string like "2d"
/// depending on the unitsstyle, see docs at http://apple.co/1ox2sOX
/// inject an existing NSDateComponentsFormatter() for performance
func relativeDateInterval(date: NSDate,
unitsStyle: NSDateComponentsFormatterUnitsStyle,
formatter: NSDateComponentsFormatter) -> String? {
// inspired by top answer at http://bit.ly/1TzMQqV
let formatter = NSDateComponentsFormatter()
formatter.unitsStyle = unitsStyle //.Abbreviated, .Full, ...
formatter.includesApproximationPhrase = false