This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var tesseract = require('node-tesseract'); | |
var options = { | |
l: 'eng', | |
psm: 1 | |
}; | |
tesseract.process('/home/tesseract/IMG_4918.jpg', options, function(err, text) { | |
if (err) { | |
console.error(err); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"io" | |
"net/http" | |
"reflect" | |
"golang.org/x/net/websocket" | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ViewController: UIViewController { | |
@IBOutlet weak var square: UIView! | |
var squareMidpoint:CGPoint = CGPointZero | |
@IBAction func handlePan(recognizer: UIPanGestureRecognizer) { | |
let hitInRect = CGRectContainsPoint(square.frame, recognizer.locationInView(self.view)) | |
let isMoving = (squareMidpoint != CGPointZero) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
self.timer.invalidate() | |
let value = ((Float((random()&1000)) / 100) % 5) + 0.4 | |
let rndTimeout = NSTimeInterval(value) | |
self.timer = NSTimer.scheduledTimerWithTimeInterval(rndTimeout, target: self, selector: Selector("showActivity:"), userInfo: nil, repeats: true) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let escape = "\u{001B}[" | |
let none = escape + "0m" | |
let red = escape + "0;31m" | |
let green = escape + "0;32m" | |
let yellow = escape + "0;33m" | |
println("\(red)Everything \(green)or \(yellow)nothing\(none).") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func createAuthHandler() -> NXOAuth2PreparedAuthorizationURLHandler { | |
return { (url: NSURL!) -> Void in | |
let sourceScript = "tell application \"Safari\"\n" | |
+ " open location \"\(url.absoluteString!)\"\n" | |
+ " activate\n" | |
+ "end tell\n" | |
var err : NSDictionary? | |
let script = NSAppleScript(source: sourceScript)! | |
if script.compileAndReturnError(&err) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# Brute force method of grabbing 200 characters preceeding first <blockquote> element | |
# | |
p = Post.last | |
parts = p.split_as_html | |
root = Nokogiri::HTML.fragment(parts.first.raw_content) | |
bq = root.search('blockquote')[1] | |
test_string = root.inner_html[(root.inner_html.index(bq.to_html) - 200)...(root.inner_html.index(bq.to_html))] | |
# ">\n<br><br><div class=\"gmail_quote\">On Tue, Jun 29, 2014 at 11:19 AM, John Smith <span dir=\"ltr\">< |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void)textDidChange:(NSNotification *)aNotification | |
{ | |
NSTextView *textView = self.detailTextView; | |
NSString *contents = textView.textStorage.string; | |
NSRange selectionRange = textView.selectedRange; | |
if (selectionRange.length == 0 && contents.length > 0) { | |
NSString *possibleMatch = [contents substringWithRange:NSMakeRange(selectionRange.location - 1, 1)]; | |
if ([possibleMatch isEqualToString:@"{"]) { | |
[textView complete:nil]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
NSMutableArray *albumIDs = [[NSMutableArray alloc] initWithCapacity:1000]; | |
for (MPMediaItemCollection *collection in items) { | |
@autoreleasepool { | |
MPMediaItem *props = collection.representativeItem; | |
NSString *albumTitle = [props valueForProperty:MPMediaItemPropertyAlbumTitle]; | |
NSString *artistName = [props valueForProperty:MPMediaItemPropertyAlbumArtist]; | |
MPMediaItemArtwork *artwork = [props valueForProperty:MPMediaItemPropertyArtwork]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (NSString *)schemaFor:(NSString *)dbFile | |
{ | |
sqlite3 *db; | |
NSString *query = @"select name, sql from sqlite_master where type = 'table'"; | |
NSString *result; | |
if (sqlite3_open([dbFile UTF8String], &db) == SQLITE_OK) { | |
sqlite3_stmt *stmt; | |
if (sqlite3_prepare_v2(db, [query UTF8String], -1, &stmt, NULL) == SQLITE_OK) { | |
if (sqlite3_step(stmt) == SQLITE_ROW) { |