Skip to content

Instantly share code, notes, and snippets.

@abhibeckert
abhibeckert / gist:6503790a8735979751ff
Last active August 29, 2015 14:08
open/create file in ruby
#!/usr/bin/ruby
require 'io/console'
for arg in ARGV
# expand the full path
file_path = File.expand_path(arg)
# if file doesn't exist, create it
let stringToDraw = self.storage.createAttributedStringWithByteRange(self.line.range)
let typesetter: CTTypesetterRef = CTTypesetterCreateWithAttributedString(stringToDraw)
Result:
error: cannot convert the expression's type 'CTTypesetter!' to type 'CFAttributedString!'
let typesetter: CTTypesetterRef = CTTypesetterCreateWithAttributedString(stringToDraw)
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
func foo(closure: Void -> Void)
{
closure()
}
// correct syntax
foo({
println("Hello")
})
<?php
$substitution = '5tv0WiPg2YoSNCRzzBUZc7Bozp2WhLmODSMmc8qlTNh8MdUJVyPx9lj3vngJzFn';
$regexPattern = str_replace('*', $substitution, $customRulePattern); // replace "*" with random substitution, to avoid being preg_quote() escaped
$regexPattern = preg_quote($regexPattern); // escape all regex syntax
$regexPattern = str_replace('/', '\/', $regexPattern); // also escape the "/" character, since we are using that as the preg delimiter
$regexPattern = str_replace($substitution, '.*', $regexPattern); // convert $substitution into the correct regex pattern
$regexPattern = "/$regexPattern/s"; // wrap in / and add the "DOTALL" flag
$imgData = file_get_contents($path);
// determine mime type
$magicNumbersToMimeTypes = array(
'474946383761'=>'image/gif', // GIF87a type gif
'474946383961'=>'image/gif', // GIF89a type gif
'89504E470D0A1A0A'=>'image/png', // png
'FFD8FFE0'=>'image/jpeg', // JFIF jpeg
'FFD8FFE1'=>'image/jpeg', // EXIF jpeg
'FFD8FFE8'=>'image/jpeg', // SPIFF jpeg
//
// DuxTextView.m
// DuxTextView
//
// Created by Abhi Beckert on 19/10/2013.
// Copyright (c) 2013 Abhi Beckert. All rights reserved.
//
#import "DuxTextView.h"
- (void)applicationDidEnterBackground:(UIApplication *)application
{
[self update];
self.backgroundTaskIdentifier =
[application beginBackgroundTaskWithExpirationHandler:^(void) {
@autoreleasepool {
NSLog(@"begin in background after 10 minutes");
[motionManager stopAccelerometerUpdates];
motionManager.accelerometerUpdateInterval = 0.2f;
[self update2];
#import <Foundation/Foundation.h>
#import <Carbon/Carbon.h>
int main(int argc, const char * argv[])
{
@autoreleasepool {
// get list of running apps
NSMutableArray *runningApps = [NSMutableArray array];
@import <Foundation/CPObject.j>
@import "PageView.j"
@import "PhotoInspector.j"
@implementation AppController : CPObject
{
}
@abhibeckert
abhibeckert / gist:5053904
Created February 28, 2013 03:18
takes an image and crops it to f it your displays on OS X
//
// main.m
// span-image-across-displays
//
// Created by Abhi Beckert on 2013-2-19.
// Copyright (c) 2013 Abhi Beckert. All rights reserved.
//
#import <Cocoa/Cocoa.h>