Skip to content

Instantly share code, notes, and snippets.

@rupey
rupey / gist:f1429adab0877506c9fb
Created Aug 10, 2014
iTunes Store API rating count retriever snippet
View gist:f1429adab0877506c9fb
#pragma mark - iTunes Store API
#define ITUNES_APP_ID @"870393074"
- (void)updateReviewCount
{
NSString *countryCode = [[[NSLocale currentLocale] objectForKey: NSLocaleCountryCode] lowercaseString];
NSString *url = [NSString stringWithFormat:@"https://itunes.apple.com/%@/lookup?id=%@", countryCode, ITUNES_APP_ID];
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
@0xced
0xced / MoviePlayerControllerDoneButton.h
Created Dec 17, 2014
Access the "Done" button of a MPMoviePlayerController
View MoviePlayerControllerDoneButton.h
#import <MediaPlayer/MediaPlayer.h>
/**
* Example usage:
* UIButton *doneButton = MoviePlayerControllerDoneButton(moviePlayerViewController.moviePlayer);
* [doneButton setTitle:@"✖" forState:UIControlStateNormal];
* doneButton.titleLabel.font = [UIFont systemFontOfSize:30];
*/
extern UIButton * MoviePlayerControllerDoneButton(MPMoviePlayerController *moviePlayerController);
@henry0312
henry0312 / mingw.sh
Created Nov 27, 2011
Build MinGW Cross Compiler on Mac OS X Lion
View mingw.sh
#!/bin/sh
# 初期設定
WORK=$HOME/Builds/GCC
PREFIX=$HOME/mingw
export PATH="$HOME/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin"
# ソースコードのダウンロード
if [ ! -d $WORK/src ] ; then
mkdir src
@Catfish-Man
Catfish-Man / lockcachecontention.m
Last active Jul 5, 2017
Benchmark showing how locks sharing a cache line will contend with each other
View lockcachecontention.m
#import <Foundation/Foundation.h>
#import <time.h>
#import <os/lock.h>
#define ITERS 2000
#define NSEC_PER_ITER(time) (((double)time * (double)NSEC_PER_SEC) / (double)ITERS)
#define TEST(body, name) do {\
start = [NSDate date];\
for (int i = 0; i < ITERS; i++) {\
@sjoerdvisscher
sjoerdvisscher / minimal.swift
Created Jun 28, 2017
Using Decodable to generate a minimal value
View minimal.swift
struct MinimalDecoder : Decoder {
var codingPath = [CodingKey?]()
var userInfo = [CodingUserInfoKey : Any]()
public func container<Key>(keyedBy type: Key.Type) throws -> KeyedDecodingContainer<Key> {
return KeyedDecodingContainer(MinimalKeyedDecodingContainer<Key>(decoder: self))
}
public func unkeyedContainer() throws -> UnkeyedDecodingContainer {
return DecodingContainer(decoder: self)
@msealand
msealand / CGVectorUtilities.swift
Last active Sep 4, 2019
Operator overloads to do scalar vector math on CGPoint, CGSize, CGVector.
View CGVectorUtilities.swift
import CoreGraphics
protocol VectorType {
typealias Element
var xElement: Element { get }
var yElement: Element { get }
class func buildFrom(#x: Element, y: Element) -> Self
@niun
niun / find-raspberry.sh
Last active Nov 27, 2019
Find Raspberry Pi in network (looking for MAC address vendor prefix of Raspberry Pi Foundation using nmap, awk for ipv4 / ping6, ip, grep for ipv6 neighbour discovery)
View find-raspberry.sh
sudo nmap -sP 192.168.0.0/24 | awk '/^Nmap/{ip=$NF}/B8:27:EB/{print ip}'
@omz
omz / gist:1102091
Created Jul 24, 2011 — forked from marcoarment/gist:1100959
Creating arbitrarily-colored icons from a black-with-alpha master image (iOS)
View gist:1102091
// Usage example:
// input image: http://f.cl.ly/items/3v0S3w2B3N0p3e0I082d/Image%202011.07.22%2011:29:25%20PM.png
//
// UIImage *buttonImage = [UIImage ipMaskedImageNamed:@"UIButtonBarAction.png" color:[UIColor redColor]];
// .h
@interface UIImage (IPImageUtils)
+ (UIImage *)ipMaskedImageNamed:(NSString *)name color:(UIColor *)color;
@end
View Twitter API with Curl
# create an account, create an app
# @see https://apps.twitter.com/
# retrieve the access tokens
# @see https://dev.twitter.com/oauth/reference/post/oauth2/token
# create the file ~/twitter_api
nano ~/twitter_api
Authorization: OAuth oauth_consumer_key="XXXXXX", oauth_nonce="11111111", oauth_signature="XXXXXX", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1450728725", oauth_token="99999-XXXXXX", oauth_version="1.0"
@Nihisil
Nihisil / jail.local
Last active Apr 21, 2020
Send notifications to the Slack from fail2ban
View jail.local
...
action_with_slack_notification = %(banaction)s[name=%(__name__)s, port="%(port)$
slack[name=%(__name__)s]
action = %(action_with_slack_notification)s
...
You can’t perform that action at this time.