Skip to content

Instantly share code, notes, and snippets.

@zummenix
zummenix / ios8-web-view-fix.m
Last active August 29, 2015 14:07
Fix a black frame around a pdf viewer in UIWebView.
- (void)viewDidLoad
{
[super viewDidLoad];
// ...
[self fixWebView:self.webView recursiveView:self.webView loadingFinished:NO];
}
- (void)fixWebView:(UIWebView *)webView recursiveView:(UIView *)view loadingFinished:(BOOL)finished
@zummenix
zummenix / ValidationView.m
Created April 10, 2015 10:43
Simple example with ReactiveCocoa framework.
#import "ValidationView.h"
#import "Validator.h"
@interface ValidationView ()
@property (nonatomic, weak) IBOutlet UITextField *nameTextField;
@property (nonatomic, weak) IBOutlet UITextField *passwordTextField;
@property (nonatomic, weak) IBOutlet UIActivityIndicatorView *activityView;
@property (nonatomic, weak) IBOutlet UILabel *errorLabel;
#[cfg(test)]
#[macro_use(expect)]
extern crate expectest;
#[cfg(not(test))]
fn main() {
println!("{}", mangle("This challenge doesn't seem so hard."));
}
#[cfg(test)]
#[macro_use(expect)]
extern crate expectest;
use std::fmt;
#[cfg(not(test))]
fn main() {
let data = r#"
@zummenix
zummenix / objc-enum-in-swift.swift
Created October 27, 2015 11:00
Objectvie-C / Swift interoperability issue. Failable initializer for objc enum doesn't work as expected.
// This creates UIViewAnimationCurve with invalid rawValue.
// Should be exeption while unwrapping optional value.
let curve = UIViewAnimationCurve(rawValue: 9)!
// Prints "ease in out" (This is a first variant in the enum).
switch curve {
case .EaseInOut:
print("ease in out")
case .EaseIn:
print("ease in")
@zummenix
zummenix / quicksort.rs
Created December 6, 2015 10:33
quicksort implementation using rust
fn main() {
let mut v = vec![4, 6, 7, 8, 5, 1, 2, 3, 15, 10, 35, 8, 2, 1, 201, 100];
println!("before: {:?}", v);
sort_in_place(&mut v);
println!("after: {:?}", v);
}
fn sort_in_place(a: &mut [u32]) {
match a.len() {
0 | 1 => (),
@zummenix
zummenix / lens.rs
Last active December 23, 2015 12:37
Lenses in rust (example prototype)
fn main() {
let person1 = Person::new("Ted".to_owned(), 14);
let name_lens = Person::name_lens();
let person2 = (name_lens.set)(&person1, "Doe".to_owned());
let person3 = (name_lens.set)(&person2, (name_lens.get)(&person1));
let person3 = (Person::age_lens().set)(&person3, 22);
println!("person1 {:?}", person1);
println!("person2 {:?}", person2);
@zummenix
zummenix / cc.sh
Created December 25, 2015 12:00
Repetitive task - remove provisioning profiles from ios device. Using cliclick tool.
echo "Waiting 5 seconds to prepare window. Press Ctrl-C to cancel."
sleep 5
echo "Start"
for i in {1..30}
do
echo "Click: $i"
cliclick c:690,370
cliclick c:505,525
@zummenix
zummenix / swizzle.m
Last active January 13, 2016 05:14
This fixes crash related to UIStatusBar on iOS 7.
#import <objc/runtime.h>
+ (void)swizzletouchesEndedForUIStatusBar
{
if (IS_OS_7_OR_LATER && !IS_OS_8_OR_LATER) {
Method original, swizzled;
original = class_getInstanceMethod(NSClassFromString(@"UIStatusBar"), @selector(touchesEnded:withEvent:));
swizzled = class_getInstanceMethod(self, @selector(swizzled_touchesEnded:withEvent:));
method_exchangeImplementations(original, swizzled);
@zummenix
zummenix / lazy.rs
Created January 25, 2016 10:41
Lazy evaluation prototype written in rust.
fn main() {
let mut a = lazy(|| {
println!("Hello");
546 + 233
});
println!("{:?}", a.value());
println!("{:?}", a.value());
println!("{:?}", a.value());
}