Skip to content

Instantly share code, notes, and snippets.

View yfujiki's full-sized avatar
💭
Moving around

Yuichi Fujiki yfujiki

💭
Moving around
  • Athlee Ltd
  • Japan
View GitHub Profile
@yfujiki
yfujiki / List font names
Last active October 11, 2015 23:48
List font names
NSArray *familyNames = [[NSArray alloc] initWithArray:[UIFont familyNames]];
NSArray *fontNames;
NSInteger indFamily, indFont;
for (indFamily=0; indFamily<[familyNames count]; ++indFamily) {
NSLog(@"Family name: %@", [familyNames objectAtIndex:indFamily]);
fontNames = [[NSArray alloc] initWithArray:[UIFont fontNamesForFamilyName:[familyNames objectAtIndex:indFamily]]];
for (indFont=0; indFont<[fontNames count]; ++indFont) {
NSString * fontName = [fontNames objectAtIndex:indFont];
NSLog(@" Font name: %@", fontName);
}
@yfujiki
yfujiki / Linear gradient on UIView
Created February 11, 2013 02:03
Easily add linear gradient on UIView
UIView *view = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 100)] autorelease];
CAGradientLayer *gradient = [CAGradientLayer layer];
gradient.frame = view.bounds;
gradient.colors = [NSArray arrayWithObjects:(id)[[UIColor blackColor] CGColor], (id)[[UIColor whiteColor] CGColor], nil];
[view.layer insertSublayer:gradient atIndex:0];
@yfujiki
yfujiki / Apply Mask to UIView
Last active December 16, 2015 00:19
Apply image mask to a view
CALayer *mask = [CALayer layer];
mask.contents = (id)[maskingImage CGImage];
mask.frame = (CGRect){0, 0, maskingImage.size};
view.layer.mask = mask;
view.layer.masksToBounds = YES;
@yfujiki
yfujiki / Finish background task
Created June 25, 2013 06:27
Finish background task in iOS
bgTask = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:
^{
[[UIApplication sharedApplication] endBackgroundTask:bgTask];
}];
// Now call methods doing network activity
// ...
// WHEN I KNOW THE LAST ACTION HAS COMPLETED USE THIS BLOCK OF CODE
if (bgTask != UIBackgroundTaskInvalid)
@yfujiki
yfujiki / gist:5997455
Created July 15, 2013 04:12
Take screenshot of current view
UIGraphicsBeginImageContext(view.bounds.size);
[view.layer renderInContext:
UIGraphicsGetCurrentContext()];
UIImage *destinationImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
@yfujiki
yfujiki / gist:6288465
Created August 20, 2013 23:04
Override back button without bullet frame
UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle: @" " style:UIBarButtonItemStylePlain target:nil action:nil];
self.navigationItem.backBarButtonItem = backButton;
UIImage *backButtonImage = [[UIImage imageNamed: @"img-arrow-left"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 4, 0, 36)];
[[UIBarButtonItem appearance] setBackButtonBackgroundImage:backButtonImage forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
@yfujiki
yfujiki / UIColor with hex
Created November 1, 2013 18:12
UIColor instance with hex
#define UIColorFromRGB(rgbValue) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0]
require 'optparse'
require 'pivotal-tracker'
TOKEN = 'YOUR_PIVOTAL_TOKEN'
PROJECT_IDS = [YOUR_PIVOTAL_PROJECT_ID]
TESTER_NAME = 'YOUR DEFAULT TESTER NAME (IF ANY)'
PivotalTracker::Client.token = TOKEN
def generate_options
options = {
@yfujiki
yfujiki / tile.sh
Created May 1, 2014 19:56
Create tile images of 256x256, zooming 100%, 50% and 25%
#!/bin/bash
file=$1
function tile() {
convert $file -scale ${s}%x -crop 256x256 \
-set filename:tile "%[fx:page.x/256]_%[fx:page.y/256]" \
+repage +adjoin "${file%.*}_${s}_%[filename:tile].${file#*.}"
}
s=100
tile
s=50
@yfujiki
yfujiki / gist:77df1725be99a3750634
Last active August 1, 2017 08:56
Simple dispatch_group and dispatch_semaphore sample
//: Playground - noun: a place where people can play
import Foundation
// DispatchGroup sample.
// we are waiting for all async blocks to be finished before typing "[Dispatch Group] sample has finished"
let group = DispatchGroup()
let q1 = DispatchQueue.global(qos: .background)
let q2 = DispatchQueue.global(qos: .background)