Skip to content

Instantly share code, notes, and snippets.

View cathandnya's full-sized avatar

nya cathandnya

View GitHub Profile
@cathandnya
cathandnya / rec_radiko.sh
Last active December 13, 2015 21:08 — forked from saiten/rec_radiko.sh
* 録音時間 * ffmpegでmp3に変換 * 現在時刻いれる
#!/bin/sh
playerurl=http://radiko.jp/player/swf/player_3.0.0.01.swf
playerfile=./player.swf
keyfile=./authkey.png
if [ $# -eq 1 ]; then
channel=$1
output=./$1.flv
runtime=10s
@cathandnya
cathandnya / ScalableImageView.js
Created February 25, 2013 08:00
ScalableImageView #titanium
var ScalableImageView = function(params) {
var self = Ti.UI.createImageView(params);
if (params.scaleType != 'aspectFit') {
self.addEventListener('load', function(e) {
var image = self.toBlob();
var selfBlob = self.toImage();
if (params.scaleType == 'aspectFill') {
var imageWidth = image.width;
var imageHeight = image.height;
@cathandnya
cathandnya / AutoPushButton.js
Created February 25, 2013 08:01
AutoPushButton #titanium
var AutoPushButton = function(params) {
var self = Ti.UI.createButton(params);
if (Ti.Platform.osname == 'android' && !(self.selectedBackgroundImage != null)) {
self.addEventListener('touchstart', function() {
this.opacity = 0.8;
});
self.addEventListener('touchend', function() {
this.opacity = 1.0;
});
}
@cathandnya
cathandnya / gist:5552015
Created May 10, 2013 02:24
multipart posting for Tumblr on Android.
private static void addValue(String val, String key, OutputStream strm, String boundary) throws UnsupportedEncodingException, IOException {
strm.write(boundary.getBytes("UTF-8"));
strm.write("\r\n".getBytes("UTF-8"));
strm.write("Content-Disposition: form-data; name=\"".getBytes("UTF-8"));
strm.write(key.getBytes("UTF-8"));
strm.write("\"\r\n\r\n".getBytes("UTF-8"));
strm.write(val.getBytes("UTF-8"));
strm.write("\r\n".getBytes("UTF-8"));
}
@cathandnya
cathandnya / NSData+GIF.m
Last active December 27, 2015 06:08
GIFかどうかを判断
#import "NSData+GIF.h"
@implementation NSData(GIF)
- (BOOL) isGIF {
char *bytes = (char *)[self bytes];
return [self length] >= 6 && (strncmp(bytes, "GIF87a", 6) == 0 || strncmp(bytes, "GIF89a", 6) == 0);
}
@end
//
// EndlessSummer.c
// Tumbltail
//
// Created by nya on 2013/11/05.
//
//
#import "EndlessSummer.h"
+ (void) requestPhotoPermission:(void(^)(BOOL))block {
ALAssetsLibrary* assetsLibrary = [[ALAssetsLibrary alloc] init];
ALAuthorizationStatus authStatus = [ALAssetsLibrary authorizationStatus];
if (authStatus == ALAuthorizationStatusAuthorized) {
block(YES);
} else if (authStatus == ALAuthorizationStatusDenied || authStatus == ALAuthorizationStatusRestricted) {
block(NO);
} else if (authStatus == ALAuthorizationStatusNotDetermined) {
[assetsLibrary enumerateGroupsWithTypes:ALAssetsGroupAll usingBlock:^(ALAssetsGroup *group, BOOL *stop) {
// Catch the final iteration, ignore the rest
@cathandnya
cathandnya / PopoverActionViewController.swift
Created February 2, 2016 12:32
PopoverActionViewController.swift
//
// PopoverActionViewController.swift
// ORE2
//
// Created by nya on 2/2/16.
// Copyright © 2016 cathand.org. All rights reserved.
//
import UIKit
@cathandnya
cathandnya / Preferences.java
Created March 15, 2017 03:01
JSON implementation of SharedPreferences
public class Preferences implements SharedPreferences {
File file;
JSONObject json;
Set<OnSharedPreferenceChangeListener> listeners = new HashSet<>();
public Preferences(File file) {
this.file = file;
json = loadJson();
}
import Cocoa
class AutoGrowingTextField: NSTextField {
override var intrinsicContentSize: NSSize {
let size = super.intrinsicContentSize
var r = frame
r.size.height = 10000
if let h = cell?.cellSize(forBounds: r).height {
return NSSize(width: size.width, height: h)