Skip to content

Instantly share code, notes, and snippets.

View MarcoSero's full-sized avatar

Marco Sero MarcoSero

View GitHub Profile
@MarcoSero
MarcoSero / package-ida.sh
Last active August 29, 2015 14:25 — forked from phatblat/package-ida.sh
A quick script to package up an .ipa correctly since `xcodebuild -exportArchive` misses the required SwiftSupport and WatchKitSupport folders
#!/bin/bash -e
#
# package-ipa.sh
#
# Bundles an iOS app correctly, using the same directory structure that Xcode does when using the export functionality.
#
xcarchive="$1"
output_ipa="$2"
@MarcoSero
MarcoSero / example2.js
Created May 29, 2012 19:13 — forked from anonymous/example2.js
MongoDB map reduce example 2
// suggested shell cmd line to run this:
//
// mongo --shell example2.js
//
// Note: the { out : … } parameter is for mongodb 1.8+
db.things.insert( { _id : 1, tags : ['dog', 'cat'] } );
db.things.insert( { _id : 2, tags : ['cat'] } );
db.things.insert( { _id : 3, tags : ['mouse', 'cat', 'dog'] } );
db.things.insert( { _id : 4, tags : [] } );
@MarcoSero
MarcoSero / GrabSnap.sh
Created September 7, 2012 08:00
GrabSnap -- An automated screenshot and osx iSight imaging tool
#!/bin/bash
## GrabSnap -- An automated screenshot and osx iSight imaging tool
## Requires isightcapture in the path
## grabsnap.sh [name] [interval in seconds] [number of monitors]
## [2011.04.11]
INTERVAL=60
PICTURE_DIR="$HOME/Pictures/grabsnap"
MONITORS=1
@MarcoSero
MarcoSero / rss-subscribers.sh
Created September 26, 2012 04:58
Bash script to parse Apache log for a count of RSS subscribers and email it to you
#!/bin/bash
# Schedule this to run once a day with cron. Doesn't matter what time since it parses yesterday's hits (by default).
# I only tested this on the Marco.org server, which runs CentOS (RHEL). No idea how it'll work on other distributions, but it's pretty basic.
# Required variables:
RSS_URI="/rss"
MAIL_TO="your@email.com"
LOG_FILE="/var/log/httpd/access_log"
@MarcoSero
MarcoSero / cloud_app_roulette.rb
Created September 27, 2012 19:11
A Ruby (multithreaded) Cloud App Roulette
require 'net/http'
require 'thread'
$o = [('a'..'z'),('A'..'Z'),(0..9)].map{|i| i.to_a}.flatten;
$n_found = 0
$mutex = Mutex.new
def generate
generated = (0...4).map{ $o[rand($o.length)] }.join;
end
@MarcoSero
MarcoSero / ImageResize.m
Created October 1, 2012 11:32
Objective-C Image Resizing
+ (UIImage *)imageWithImage:(UIImage *)image scaledToSize:(CGSize)newSize
{
//UIGraphicsBeginImageContext(newSize);
UIGraphicsBeginImageContextWithOptions(newSize, NO, 0.0);
[image drawInRect:CGRectMake(0, 0, newSize.width, newSize.height)];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;
}
@MarcoSero
MarcoSero / .zshrc
Created November 3, 2015 21:51
Fast git prompt
# Load oh-my-zsh first
source $ZSH/oh-my-zsh.sh
# If we are on a big repo, re-define git prompt
function git_prompt_info() {
if [[ "$(command git config --get oh-my-zsh.hide-status 2>/dev/null)" != "1" ]]; then
ref=$(command git symbolic-ref HEAD 2> /dev/null) || \
ref=$(command git rev-parse --short HEAD 2> /dev/null) || return 0
echo "$ZSH_THEME_GIT_PROMPT_PREFIX${ref#refs/heads/}$ZSH_THEME_GIT_PROMPT_SUFFIX"
fi
@MarcoSero
MarcoSero / gist:5787782
Created June 15, 2013 11:15
Class Dump iOS 7 Frameworks
# install class-dump
brew install class-dump
# dump the frameworks you're interested in
class-dump -H -o UIKit /Applications/Xcode5-DP.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS7.0.sdk/System/Library/Frameworks/UIKit.framework
class-dump -H -o SpringBoardUI /Applications/Xcode5-DP.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS7.0.sdk/System/Library/PrivateFrameworks/SpringBoardUI.framework
#define ms_invoke_block_if_not_nil(BLOCK, ...) if ((BLOCK)) {(BLOCK)(__VA_ARGS__);}
// Usage:
void (^block)(id, id, id) = void(^)(id parameter1, id parameter2, id parameter3) {
// ...
};
ms_invoke_block_if_not_nil(block, parameter1, parameter2, parameter3);
// As opposed to:
@MarcoSero
MarcoSero / foo.m
Created April 20, 2013 12:57 — forked from ryancole/foo.m
Convert NSPredicate into NSDictionary for use as a query string in an AFNetworking HTTP request
- (NSURLRequest *)requestForFetchRequest:(NSFetchRequest *)fetchRequest
withContext:(NSManagedObjectContext *)context {
// init the query string dictionary
NSMutableDictionary *queryString = nil;
// if we're given a predicate, convert it to a dictionary
if (fetchRequest.predicate) {
if ([fetchRequest.predicate isKindOfClass:[NSCompoundPredicate class]]) {