Skip to content

Instantly share code, notes, and snippets.

View dimohamdy's full-sized avatar
🏠
Working from home

Dimo Hamdy dimohamdy

🏠
Working from home
View GitHub Profile
@JadenGeller
JadenGeller / Init Bool With Int.swift
Created March 23, 2015 07:48
Cast Int to Bool in Swift
extension Bool {
init<T : IntegerType>(_ integer: T){
self.init(integer != 0)
}
}
// Now you can do this
let x = Bool(5) // true
let y = Bool(-1) // true
let z = Bool(0) // false
@raulriera
raulriera / PagingControl.js
Created April 19, 2012 02:13
Custom paging control for scrollableViews for Titanium Appcelerator
// I was unhappy about there was close to no control over the "pageControl"
// in scrollableViews, so I hacked my own
// -----
// Configuration
var pageColor = "#c99ed5";
PagingControl = function(scrollableView){
var container = Titanium.UI.createView({
height: 60
@mrtj
mrtj / BouncyButtonViewController.h
Created February 19, 2014 10:56
iOS view controller demonstrating how to create a bouncy rubber button with the new UIView method animateWithDuration:delay:usingSpringWithDamping:initialSpringVelocity:options:animations:completion: of iOS 7
#import <UIKit/UIKit.h>
@interface BouncyButtonViewController : UIViewController
@end
@johnnyclem
johnnyclem / gist:11015360
Created April 17, 2014 22:35
CMSamplebufferRef to CIImage
CVImageBufferRef cvImage = CMSampleBufferGetImageBuffer(sampleBuffer);
CIImage *ciImage = [[CIImage alloc] initWithCVPixelBuffer:cvImage];
@JadenGeller
JadenGeller / Semaphore.swift
Last active May 16, 2017 15:51
Swift Semaphore
struct Semaphore {
let semaphore: dispatch_semaphore_t
init(value: Int = 0) {
semaphore = dispatch_semaphore_create(value)
}
// Blocks the thread until the semaphore is free and returns true
// or until the timeout passes and returns false
@alejandro-isaza
alejandro-isaza / gist:5717438
Last active June 22, 2017 09:51
UIImage category to normalize image orientation by rotating an image so that it's orientation is UIImageOrientationUp. Based on http://stackoverflow.com/questions/5427656/ios-uiimagepickercontroller-result-image-orientation-after-upload/5427890#10611036
@interface UIImage (Orientation)
- (UIImage*)imageByNormalizingOrientation;
@end
@implementation UIImage (Orientation)
- (UIImage*)imageByNormalizingOrientation {
@devgeeks
devgeeks / raised-tabbar-snippet.m
Created December 2, 2012 09:23
Snippet needed to add a raised TabBar button in PhoneGap to the TabBar or NativeControls plugin on iOS
UIImage* buttonImage = [UIImage imageNamed:@"aperture-tab.png"];
UIButton* button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(0.0, 0.0, buttonImage.size.width, buttonImage.size.height);
[button setBackgroundImage:buttonImage forState:UIControlStateNormal];
[button setBackgroundImage:buttonImage forState:UIControlStateHighlighted];
CGFloat heightDifference = buttonImage.size.height - tabBar.frame.size.height;
CGPoint center = tabBar.center;
@seanlilmateus
seanlilmateus / channel.swift
Last active November 22, 2017 14:02
swift Go like channels
import Foundation
// Playground - noun: a place where people can play
class Channel<T> {
var stream: Array<T>
let queue: dispatch_queue_t
let semaphore: dispatch_semaphore_t
init() {
self.stream = []
@ohoachuck
ohoachuck / _appreviews-no-pythonista.py
Created April 19, 2013 09:39
Script for grabing AppStore review based on official Apple RSS feed. Work on Python 2.7 This script is an adaptation of _appreview.py script that was a pythonista (quick and dirty) test script. You might want to know that Apple official feed is bugged and review greater than page 10 does not appears (If I remember well). The best is to grab it f…
#!/usr/local/bin/python2.7
# Desktop version of pythonista script (no console usage nor clipboard)
# Script name: getreviews.py
# Author: Olivier HO-A-CHUCK
# License (OHO Ware): free to use modify, alter, re-use for commercial use or not! :)
# Date: Nov. 15th 2012
# Usage: _appreviews.py <appID>
# exemple: _appreviews.py 308816822
@ziggythehamster
ziggythehamster / 01.md
Created November 30, 2011 22:30
@ziggythehamster's #Titanium #Sucks Proofs

@Appcelerator #Titanium #Sucks no. 1: Child view wider than a parent view breaks out of the parent. It should get cut off by the parent.

Diagram

If you have a box that's 40x40, and position another 40x40 box within it, with top=20 and left=20, you expect to see a 40x40 box containing a 20x20 box, not two 40x40 boxes.

Titanium sucks because...

If you put a view within a view on any widget toolkit, HTML, etc. and then move the subview around within its parent, the subview should never extend beyond the boundaries of its parent. That is, it should be clipped by its parent. At least by default. This is all OK if it's supposed to work this way, but several Q&A posts suggest this exact method as a way to crop a photo. So did it get broken at some point? Are there not unit tests to determine when behavior like this is reversed? Is some way that I'm inserting this view causing it not to work consistently? Why do I see code that is exactly equal to mine