Skip to content

Instantly share code, notes, and snippets.

View bogren's full-sized avatar
🎧
-

Emil Bogren bogren

🎧
-
View GitHub Profile
import Foundation
let data = try
String(contentsOfFile: "input", encoding: .utf8)
.components(separatedBy: .newlines)
struct Seat: Hashable {
let row: Int
let col: Int
import Foundation
let lines = try
String(contentsOfFile: "input", encoding: .utf8)
.components(separatedBy: .newlines)
.split(separator: "")
var part1 = 0
for line in lines {
var set = Set<Character>()
@bogren
bogren / UITextViewPlaceholder.swift
Created October 14, 2019 13:11 — forked from tijme/UITextViewPlaceholder.swift
The correct way to implement a placeholder in a UITextView (Swift)
//
// UITextViewPlaceholder.swift
// TextViewPlaceholder
//
// Copyright (c) 2017 Tijme Gommers <tijme@finnwea.com>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
{
"bold_folder_labels": true,
"color_scheme": "Packages/Theme - Flatland/Flatland Dark.tmTheme",
"draw_white_space": "selection",
"font_size": 12.0,
"highlight_line": true,
"ignored_packages":
[
"Vintage"
],
@bogren
bogren / CropBottomPart
Created January 13, 2015 15:18
Crop to keep bottom part of UIImage
- (UIImage *)cropImage:(UIImageView *)image {
UIGraphicsBeginImageContext(CGSizeMake(320, 64));
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextTranslateCTM(context, 0, -image.frame.size.height + 64);
[image.layer renderInContext:context];
UIImage *subImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return subImage;
-(UIImage *)convertViewToImage
{
UIGraphicsBeginImageContext(self.view.bounds.size);
[self.view drawViewHierarchyInRect:self.view.bounds afterScreenUpdates:YES];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
@bogren
bogren / keybase
Last active October 18, 2016 14:35
### Keybase proof
I hereby claim:
* I am bogren on github.
* I am eyem (https://keybase.io/eyem) on keybase.
* I have a public key ASBci_b1nEgdtoEXpGDICBCIvjoqNASc5rnLXTzS0vhiXQo
To claim this, I am signing this object:
@bogren
bogren / keyhax
Last active May 4, 2017 08:16
A hax used to pre-load the keyboard
/*
* Lag free keyboard init - Used in appdelegate
*/
UITextField *lagFreeField = [[UITextField alloc] init];
[self.window addSubview:lagFreeField];
[lagFreeField becomeFirstResponder];
[lagFreeField resignFirstResponder];
[lagFreeField removeFromSuperview];