Skip to content

Instantly share code, notes, and snippets.

@akisute
akisute / gist:1141953
Created August 12, 2011 12:41
Create an animated gif file from images in iOS
#import <UIKit/UIKit.h>
#import <ImageIO/ImageIO.h>
#import <MobileCoreServices/MobileCoreServices.h>
- (void)exportAnimatedGif
{
UIImage *shacho = [UIImage imageNamed:@"shacho.png"];
UIImage *bucho = [UIImage imageNamed:@"bucho.jpeg"];
NSString *path = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject] stringByAppendingPathComponent:@"animated.gif"];
@akisute
akisute / admin.py
Created August 6, 2013 11:40
How to use django.contrib.admin.models.LogEntry
# -*- coding: utf-8 -*-
import datetime
from django.contrib.admin.models import LogEntry, ADDITION, CHANGE
class MoniterLog(admin.ModelAdmin):
#dt_utc = datetime.datetime.strptime('action_time', '%Y-%m-%d %H:%M:%S')
#str_utc = 'action_time'
#dt_utc = datetime.datetime.strptime(str_utc, '%Y-%m-%d %H:%M:%S')
#dt_jst = dt_utc + datetime.timedelta(0,3600)
#str_jst = dt_jst.strftime('%Y/%m/%d %H:%M:%S')
@akisute
akisute / BPPrivateWebView.h
Created September 12, 2011 00:40
An UIWebView subclass which uses WebKit private APIs to delegate authentications.
//
// BPPrivateWebView.h
// BPUI
//
// Created by akisute on 11/09/11.
//
/*
Copyright (c) 2011 Masashi Ono.
Permission is hereby granted, free of charge, to any person obtaining a copy of
@akisute
akisute / AsyncSenTestingKitTests.h
Created March 17, 2012 02:23
SenAsyncTestCase - Asynchronous capable SenTestCase
//
// AsyncSenTestingKitTests.h
// AsyncSenTestingKitTests
//
// Created by 小野 将司 on 12/03/17.
// Copyright (c) 2012年 AppBankGames Inc. All rights reserved.
//
#import <SenTestingKit/SenTestingKit.h>
#import "SenAsyncTestCase.h"
@akisute
akisute / gist:7670871
Created November 27, 2013 04:59
PostprocessBuildPlayer for Unity, Written in Ruby.
#!/usr/bin/env ruby
#
# PostprocessBuildPlayer version 2
# Tested on Ruby 1.8.7, Gem 1.3.6, and xcodeproj 0.4.1
# Created by akisute (http://akisute.com)
# Licensed under The MIT License: http://opensource.org/licenses/mit-license.php
#
require 'rubygems'
# least require version, doesn't work in 0.3.X or less
@akisute
akisute / UIWebView+Additions.h
Created February 27, 2011 15:32
UIWebView addition to enable/disable scrolling
#import <UIKit/UIKit.h>
@interface UIWebView (Additions)
/*!
@abstract Enable/Disable the receiver from scrolling.
*/
@property (nonatomic, assign) BOOL webViewScrollEnabled;
@akisute
akisute / iPad Air 2
Last active November 16, 2018 02:46
Handling Size Class, UITraitEnvironment, UIContentContainer on iOS 9 (beta 1)
////////////////
// on iPad Air 2
////////////////
// Boot as portrait
2015-06-15 19:57:47.597 ios9[16003:229076] viewDidLoad()
2015-06-15 19:57:47.598 ios9[16003:229076] viewWillAppear - false
2015-06-15 19:57:47.601 ios9[16003:229076] traitCollectionDidChange - nil
2015-06-15 19:57:47.602 ios9[16003:229076] viewWillLayoutSubviews()
2015-06-15 19:57:47.602 ios9[16003:229076] viewDidLayoutSubviews()
@akisute
akisute / LinqFTW.cs
Created May 5, 2012 11:06
Use System.Linq to map/reduce lists
using UnityEngine;
using System.Collection.Generics;
using System.Linq;
public void MapExample() {
// System.Linq.Queryable.Selectメソッドがいわゆるmapに相当するメソッドになります
List<UnityEngine.Object> allResources = new List<UnityEngine.Object>(Resources.FindObjectsOfTypeAll(typeof(UnityEngine.Object)));
IEnumerable<string> allResourceNames = allResources.Select(x => x.name);
Debug.Log(string.Join("\n", allResourceNames.ToArray()));
}
@akisute
akisute / SomeWebViewController.m
Last active July 30, 2018 01:56
Dismissing fullscreen movie player from <video> tag in UIWebView
- (void)exitFullScreenVideo
{
// Works in iOS, not sure in OS X
[self.webView stringByEvaluatingJavaScriptFromString:@"Array.prototype.forEach.call(document.getElementsByTagName('video'),function(v){v.webkitExitFullscreen();});"];
// Didn't work in iOS, works in OS X
[self.webView stringByEvaluatingJavaScriptFromString:@"if(document.webkitFullscreenElement){document.webkitExitFullscreen();}"];
}
@akisute
akisute / SomeWebViewController.m
Last active July 27, 2018 04:27
Dismissing fullscreen movie player from <video> tag in UIWebView with animation and completion handler
/*
WARNING: PRIVATE API CALLS
WARNING: FORCEFUL MEMORY MANAGEMENT
highly recommend to avoid using this code
*/
- (void)exitFullScreenVideo:(BOOL)animated completion:(void (^)(void))completion
{
/*
iOS 6~7の場合
本ViewControllerの上にMPInlineVideoFullscreenViewControllerがfullscreen modalで表示されるような挙動になるので