Skip to content

Instantly share code, notes, and snippets.

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

Nikhil Nigade dezinezync

🏠
Working from home
View GitHub Profile
@dezinezync
dezinezync / test1.js
Created August 11, 2012 19:23 — forked from pec1985/test1.js
Optimizing Appcelerator's Titanium
/**
* Test #1
* Adding 10,000 Ti.UI.TableViewRows to a Ti.UI.TableView
* The rows have the Ti.UI.iPhone.TableViewCellSelectionStyle.BLUE constant in them
*
* Total time in my Mac: 1228ms
*/
var win = Ti.UI.createWindow({
backgroundColor: '#ccc'
@dezinezync
dezinezync / gist:4034684
Created November 7, 2012 21:40 — forked from daneden/gist:4032573
Sass media queries and @extend
// Fairly safe way to visually hide content, but make it accessible to screen readers
.visually-hidden {
position: absolute;
left: -9999px;
height: 1px;
}
@media screen and (max-width: 700px) {
// Again, accessible to screen readers
// Example: <a href="/login" class="icon icon-twitter"><span class="mobile-offscreen">Single-click </span> log in with Twitter</a>
#eyebrow { display: none !important; }
body.with-eyebrow { padding-top: 49px !important; background: none !important; }
body.with-eyebrow #global-nav { top: 0 !important;}
body.with-eyebrow #subnav-refresh {top: -71px !important; }
body.with-eyebrow #view-holder {margin-top: -71px !important; }
redis-cli KEYS "prefix:*" | xargs redis-cli DEL
- (BOOL)stringContainsEmoji:(NSString *)string {
__block BOOL returnValue = NO;
[string enumerateSubstringsInRange:NSMakeRange(0, [string length]) options:NSStringEnumerationByComposedCharacterSequences usingBlock:
^(NSString *substring, NSRange substringRange, NSRange enclosingRange, BOOL *stop) {
const unichar hs = [substring characterAtIndex:0];
// surrogate pair
if (0xd800 <= hs && hs <= 0xdbff) {
if (substring.length > 1) {
const unichar ls = [substring characterAtIndex:1];
// cheers to @stroughtonsmith for helping out with this one
UIColor *barColour = [UIColor colorWithRed:0.13f green:0.14f blue:0.15f alpha:1.00f];
UIView *colourView = [[UIView alloc] initWithFrame:CGRectMake(0.f, -20.f, 320.f, 64.f)];
colourView.opaque = NO;
colourView.alpha = .7f;
colourView.backgroundColor = barColour;
self.navigationBar.barTintColor = barColour;
## The Problem
Standard practices say no non-root process gets to talk to the Internet on a port less than 1024. How, then, could I get Node talking on port 80 on EC2? (I wanted it to go as fast as possible and use the smallest possible share of my teeny tiny little micro-instance's resources, so proxying through nginx or Apache seemed suboptimal.)
## The temptingly easy but ultimately wrong solution:
Alter the port the script talks to from 8000 to 80:
}).listen(80);
- (void)reposition {
// https://developer.apple.com/library/ios/#qa/qa2010/qa1688.html
// tl;dr Only the first subview in the window receives orientation changes.
// So we apply a transform manually to rotate the view, and change the origin of the frame so
// that it remains in a top-center position for the user.
UIInterfaceOrientation orientation =
[UIApplication sharedApplication].statusBarOrientation;
UIWindow *keyWindow = [[UIApplication sharedApplication] keyWindow];
CGAffineTransform viewTransform = CGAffineTransformIdentity;
- (NSString *)tableView:(UITableView *)tableView titleForSwipeAccessoryButtonForRowAtIndexPath:(NSIndexPath *)indexPath {
return @"More";
}
- (void)tableView:(UITableView *)tableView swipeAccessoryButtonPushedForRowAtIndexPath:(NSIndexPath *)indexPath {
NSLog(@"I wanted to be a pretty public API, but then time ran out and they forgot me...");
// Hide the More/Delete menu.
[self setEditing:NO animated:YES];
}
// For details, see http://mindsea.com/2012/12/18/downscaling-huge-alassets-without-fear-of-sigkill
#import <AssetsLibrary/AssetsLibrary.h>
#import <ImageIO/ImageIO.h>
// Helper methods for thumbnailForAsset:maxPixelSize:
static size_t getAssetBytesCallback(void *info, void *buffer, off_t position, size_t count) {
ALAssetRepresentation *rep = (__bridge id)info;
NSError *error = nil;