Skip to content

Instantly share code, notes, and snippets.

@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:
@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

@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");
*/
@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();
);
@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
@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 / gist:3181214
Created July 26, 2012 09:31
优化字符串定义的宏
#define OC(str) [NSString stringWithCString:(str) encoding:NSUTF8StringEncoding]
#ifdef DEBUG
# define LOG(fmt, ...) do { \
NSString* file = [[NSString alloc] initWithFormat:@"%s", __FILE__]; \
NSLog((@"%@(%d) " fmt), [file lastPathComponent], __LINE__, ##__VA_ARGS__); \
[file release]; \
} while(0)
# define LOG_METHOD NSLog(@"%s", __func__)
# define LOG_CMETHOD NSLog(@"%@/%@", NSStringFromClass([self class]), NSStringFromSelector(_cmd))
- (void)_updateResults:(void (^)(void))block caller:(dispatch_queue_t)callerqueue
{
__unsafe_unretained NUData* wself = self;
dispatch_sync(_serial_results_queue, ^{
NSManagedObjectContext* ctx = updateContext;
__block NSArray* results = nil;
[ctx performBlockAndWait:^{
@flandy84
flandy84 / gist:3183844
Created July 26, 2012 19:05
"modern Objective-C" syntax
//"modern Objective-C" syntax
//new enum-macros for better autocompletion, switch statement, more precise warnings, ...
typedef NS_ENUM(NSInteger, MyViewContentMode) {
MyViewContentModeLeft,
MyViewContentModeRight,
MyViewContentModeTopLeft,
MyViewContentModeTopRight,
@naiveal
naiveal / gist:3187150
Created July 27, 2012 09:48
printfTreeLevelOfView
void printfTreeLevelOfView(UIView *view, int maxLevel)
{
UIView *tempView;
NSArray *subViews = [view subviews];
static int level = 0;
level++;
for(tempView in subViews)
{
if ( level <= maxLevel) {
for (int i = 0; i < level; i++)