Skip to content

Instantly share code, notes, and snippets.

@tsbob
tsbob / gist:3180668
Created July 26, 2012 07:03
Singletons 实现
Here's what the GCD (and ARC) version looks like:
+ (id)sharedInstance
{
static dispatch_once_t pred = 0;
__strong static id _sharedObject = nil;
dispatch_once(&pred, ^{
_sharedObject = [[self alloc] init]; // or some other init method
});
return _sharedObject;
}
@tsbob
tsbob / ExampleClass.m
Created July 26, 2012 07:03 — forked from lukeredpath/ExampleClass.m
Macro for creating your "shared instance" using GCD
@implementation MySharedThing
+ (id)sharedInstance
{
DEFINE_SHARED_INSTANCE_USING_BLOCK(^{
return [[self alloc] init];
});
}
@end
@jblocksom
jblocksom / embeddedJS.m
Created July 25, 2012 19:10
Fix UIWebView chapter JavaScript
- (void)motionBegan:(UIEventSubtype)motion
withEvent:(UIEvent *)event
{
#define STRINGIFY(js) #js
NSString *js = @ STRINGIFY(
var $elements = $('.leftArea_container>div'),
$rand = $elements.not(':first').eq(Math.floor(Math.random() * $elements.length));
$rand.slideUp(500,function(){ $(this).insertBefore($elements.first()); }).slideDown();
);
@codeswimmer
codeswimmer / DebugAlert.h
Created July 24, 2012 01:01 — forked from chunkyguy/DebugAlert.h
Debugging with UIAlertViews
#define POP_ALERT(title, msg) [[[[UIAlertView alloc] initWithTitle:title message:msg delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]autorelease] show]
/*
Usage:
POP_ALERT(@"Title Here", @"Message Here");
*/
@ttezel
ttezel / gist:3160712
Created July 22, 2012 19:00
Some things I think will happen by 2020

#Some things I think will happen by 2020:

  1. The Voice interface will be mastered. We will be talking to computers and they will understand the meaning/context of our words, and help us live our lives. Siri is where it starts.

  2. Fully articulable, brain-controlled artificial limbs will be in existence. Amputees will have limbs replaced with an artificial limb, and continue to live fully enabled. Price would still be high at this time. There is already great progress in this area.

  3. Driverless cars will start to gain popularity. People who purchase an autonomous vehicle (e.g. Google's driverless car) will be sitting in their cars, working/entertaining themselves with mobile devices while they are driven around. Google is close to launching their autonomous car for sale. They are way ahead of the competition. Google will be heavy in the automotive game. They are lobbying to legalize Autonomous Vehicles in the US.

  4. We will have devices with morphable, touchable interface

@ViktorOgnev
ViktorOgnev / gist:3160335
Created July 22, 2012 17:12
Check sudoku - solve sudoku
def check_sudoku(grid, p_info = False, gridsize = 9):
'''sudoku checker - enter True as second func. argument
to print more info
about check failures'''
def check_sudoku_complete_results(grid, gridsize = 9):
if type(grid) != list: return None, 'function accepts list, got %s instead' % (str(type(grid)))
if gridsize % 3 != 0: return None, 'incorrect size'
if len(grid) != gridsize:
@kenota
kenota / gist:3157873
Created July 22, 2012 01:33
builder vs buffer
package com.binarybuffer.test.bufferbuilder;
import org.apache.commons.math3.stat.descriptive.StatisticalSummary;
import org.apache.commons.math3.stat.descriptive.SummaryStatistics;
import org.junit.Test;
/**
* Unit test for simple App.
@jake7864
jake7864 / StopWatch.java
Created July 14, 2012 13:53
a small simple stop watch program, you specify a time and when started it will decrease the time by 1 a second
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.DecimalFormat;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
@fousa
fousa / content.m
Created July 12, 2012 10:09
GCD Singleton
+ (MyClass *)sharedInstance {
static dispatch_once_t _predicate;
static MyClass *_sharedInstance = nil;
dispatch_once(&_predicate, ^{
_sharedInstance = [self new];
});
return _sharedInstance;
}
@kaorimatz
kaorimatz / tags-java.sh
Created July 10, 2012 18:01
Generate a cross reference for the maven project
#!/bin/sh
CSCOPE_OUT_DIR=$HOME/.cscope
CTAGS_OUT_DIR=$HOME/.tags
NAMEFILE=/tmp/java.files
if [ $# != 1 ]; then
echo "usega: $0 project_dir"
exit 1
fi;