Skip to content

Instantly share code, notes, and snippets.

View niw's full-sized avatar
🐱
Meow

Yoshimasa Niwa niw

🐱
Meow
View GitHub Profile
@niw
niw / sweep_addressbook_images.sh
Created October 17, 2011 08:54
Cleaning up your massy ~/Library/Application Support/AddressBook/Images
#!/bin/sh
if [ ! -f AddressBook-v22.abcddb ]; then
echo "Hmm, pleace cd to the dir which has AddressBook-v22.abcddb."
exit 1;
fi
find Images -type f|sed 's/^Images\///g'|sort > images_ids
echo "SELECT ZUNIQUEID FROM ZABCDRECORD;"|sqlite3 AddressBook-v22.abcddb|grep ABPerson|awk -F: '{print $1}'|sort > real_ids
@niw
niw / cleanup.command
Created November 15, 2011 10:36
Cleanup rich text clipboard content to plain text.
#!/bin/sh
__CF_USER_TEXT_ENCODING=`printf '0x%X' \`id -u\``:0x8000100:14
pbpaste|pbcopy
@niw
niw / create_apple_push_pem.sh
Created January 7, 2012 04:53
Create combined PEM file from private key and certificate for Apple Push Notification.
#!/bin/sh
if [ -z "$1" -o "$1" = "-h" -o "$1" = "--help" ]; then
echo "Usage: $0 private_key.p12 certificate.{p12, der}"
echo "You can export the private key (and certificate) in PKCS12 format from Keychain.app."
exit 0
fi
# Create private key in PEM format from PKCS12 format without password.
openssl pkcs12 -in "$1" -nocerts -nodes -out _key.pem
@niw
niw / import_instapaper_to_redability.rb
Created March 7, 2012 11:58
A tiny script to import items from Instapaper to Readability
#!/usr/bin/env ruby
require 'csv'
require 'net/smtp'
require 'resolv'
# We need a specific version of eventmachine due to apply a patch.
gem 'eventmachine', '0.12.10'
require 'eventmachine'
@niw
niw / strip_color_sync_profile.m
Created March 31, 2012 22:48
Remove Color Sync Profile from image using CoreGraphics
#import <Cocoa/Cocoa.h>
@interface StripColorSyncProfile : NSObject
+ (NSData *)imageDataWithoutColorSyncProfile:(NSData *)data;
@end
@implementation StripColorSyncProfile
+ (NSData *)imageDataWithoutColorSyncProfile:(NSData *)data
{
CGImageSourceRef cf_sourceImage = CGImageSourceCreateWithData((__bridge CFDataRef)data, NULL);
@niw
niw / gist:2269420
Created March 31, 2012 23:05
Gmail(とか)を独立したアプリとしてiPhoneの画面に追加するブックマークレット
1. GmailをSafariで開く
2. 次の行をjavascript:から最後までコピーしてアドレスバーに貼り付けてGo
javascript:(function()%7Bvar%20d=document,m=d.createElement('meta');m.name='apple-mobile-web-app-capable';m.content='yes';d.getElementsByTagName('head').item(0).appendChild(m);alert('Ready.');%7D)();
3. その後+ボタンでホーム画面に追加
4. Gmailが独立したアプリになる
5. 便利
@niw
niw / freeze_webkit_for_app.sh
Created June 27, 2012 01:05
Freeze WebKit frameworks for the specific application.
#!/bin/sh
if [ "$1" = "-h" -o "$1" = "--help" ]; then
echo "Usage: freeze_webkit_for_app.sh [path]"
echo "ARGUMENTS"
echo " path Path to the application."
echo "OPTIONS"
echo " APPLICATION_PATH Path to the application."
echo " WEBKIT_REVISION Revision of WebKit framework nightly build."
exit 1
@niw
niw / MIT-LICENSE.txt
Created August 25, 2012 12:48
Toggle Host AP Mode on Mac OS X, Using undocumented APIs.
Copyright (C) 2012 Yoshimasa Niwa
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
@niw
niw / check_updates.applescript
Created December 6, 2012 09:34
Login to iTunes, Check Apps updates
set APPLE_ID to "YOUR APPLE ID"
set APPLE_ID_PASSWORD to "YOUR APPLE ID PASSWORD"
tell application "iTunes" to activate
tell application "System Events"
tell process "iTunes"
set itunes to it
-- Make sure iTunes is ready
if title of window 1 is not equal to "iTunes" then
@niw
niw / FastKeyRepeat.m
Created January 4, 2013 08:39
Preview code to load Keyboard preference pane with a faster key repeat settings.
#import <PreferencePanes/PreferencePanes.h>
#import <objc/message.h>
void exchangeInstanceMethodImplementations(NSString *className, SEL originlSelector, SEL replacementSelector)
{
Class class = NSClassFromString(className);
if(class) {
Method originalMethod = class_getInstanceMethod(class, originlSelector);
Method replacementMethod = class_getInstanceMethod(class, replacementSelector);
method_exchangeImplementations(originalMethod, replacementMethod);