Skip to content

Instantly share code, notes, and snippets.

View leontiy's full-sized avatar

Leon Deriglazov leontiy

  • JPMorgan Chase & Co.
  • London, UK
View GitHub Profile
func awakeFromNib() {
super.awakeFromNib()
self.titleLabel.reactive.text <~ self.viewModel.map { $0?.title }
self.label.reactive.text <~ self.viewModel.map { $0?.text }
self.imageView.reactive.image <~ self.viewModel.producer.flatMap(.latest) {
downloadImage($0.imageUrl).map(Optional.some).prefix(value: nil)
}
}
final class ProductTableViewCell: UITableViewCell {
@IBOutlet var label: UILabel!
@IBOutlet var imageView: UIImageView!
@IBOutlet var titleLabel: UILabel!
let viewModel: MutableProperty<Product?>
var disposable: Disposable?
deinit() {
// View Model layer
final class Product {
let title: String
let text: String
let imageUrl: URL
// ...
}
// Networking layer
func downloadImage(url: URL) -> SignalProducer<UIImage, NSError> {
@leontiy
leontiy / gist:685a5a7e72efcbdf415c
Created October 22, 2014 16:59
UIStatusBar method selectors
_adjustDoubleHeightTextVisibility
_backgroundFrameForAttributes:
_backgroundView
_beginDisablingRasterizationForReason:
_clearOverrideHeight
_crossfadeToNewBackgroundView
_crossfadeToNewForegroundViewWithAlpha:
_currentComposedData
_currentComposedDataForStyle:
_currentStyleAttributes
@leontiy
leontiy / merge_localizations.py
Last active August 29, 2015 14:01
Merge localisation files
#!/usr/bin/python
import re
import sys
import codecs
generated_regex = re.compile(r"/\*(?P<comment>.*?)\*/[\n\r]*\"(?P<key>.*?)\"\s*=\s*\"(?P<value>.*?)\";", re.S)
handcrafted_regex = re.compile(r"\"(?P<key>.*?)\"\s*=\s*\"(?P<value>.*?)\";(?P<comment>)", re.S)
def parse(file_name, regex, encoding = "utf-8"):
@leontiy
leontiy / lj-to-dayone
Last active December 26, 2021 18:24
A (not so) simple python script to import Live Journal's XML export files to Day One for Mac.
#!/usr/bin/python
# HOW TO USE THIS SCRIPT:
# 0. Install [Day One CLI](http://dayoneapp.com/tools/)
# 1. Get your XML files using [Live Journal's export form](http://www.livejournal.com/export.bml)
# 2. Run this script against every exported file (yes, you get tons of XML files — it's a good idea to automate this step). The shell command should look like this
# `ls -1 *.xml | xargs -n1 lj-to-dayone -u username`
# assuming you have all your XMLs in current directory and lj-to-dayone on your PATH (or in the same directory).
# Author: Leonty Deriglazov, 14/07/2013.
@leontiy
leontiy / UIDeviceHardware.h
Created April 27, 2012 04:06 — forked from Jaybles/UIDeviceHardware.h
UIDeviceHardware - Determine iOS device being used
//
// UIDeviceHardware.h
//
// Used to determine EXACT version of device software is running on.
#import <Foundation/Foundation.h>
@interface UIDeviceHardware : NSObject
+ (NSString *) platform;
@leontiy
leontiy / .gitignore
Created October 18, 2011 06:53
My global .gitignore file.
.DS_Store
.svn
*.mode1v3
*.pbxuser
project.xcworkspace
@leontiy
leontiy / .sh
Created June 27, 2010 02:28
.zshrc
export LC_CTYPE=en_US.UTF-8
export PATH=$PATH:~/scripts:/opt/local/bin:/Developer/usr/bin:/usr/local/texlive/2009/bin/universal-darwin:/usr/local/git/bin/
export EDITOR='mate -w'
export GIT_EDITOR="mate -wl1"
export LESSEDIT='mate -l %lm %f'
PS1="%n@%m:%20~%#> "
autoload -U compinit
compinit
zstyle ':completion:*:descriptions' format '%U%B%d%b%u'
zstyle ':completion:*:warnings' format '%BSorry, no matches for: %d%b'
NSString * path = [[NSBundle mainBundle] pathForResource:<#Resource name#> ofType:@"plist"];
NSData * plistXML = [[NSFileManager defaultManager] contentsAtPath: path];
NSString * errorDesc = nil;
NSPropertyListFormat format;
<#Variable name#> = (<#Type of top level element#> *)[NSPropertyListSerialization propertyListFromData:plistXML mutabilityOption:NSPropertyListImmutable format:&format errorDescription:&errorDesc];
if (nil == <#Variable name#>) {
NSLog(@"Can not load <#What#>.");
if (errorDesc) {
NSLog(@"Error description: %@", errorDesc);
[errorDesc release]; errorDesc = nil;