19840618® http://19840618.com a one-man programming firm posterous.com Thu, 29 Dec 2011 13:00:00 -0800 OSX GCC Installer for 10.7 http://19840618.com/osx-gcc-installer-for-107 http://19840618.com/osx-gcc-installer-for-107

https://github.com/kennethreitz/osx-gcc-installer/downloads

Permalink | Leave a comment  »

]]>
http://posterous.com/images/profile/missing-user-75.png http://posterous.com/users/5ebESf1GcYud tomonaga tomonaga
Wed, 28 Dec 2011 07:28:00 -0800 -fno-objc-arc http://19840618.com/fno-objc-arc http://19840618.com/fno-objc-arc

http://developer.apple.com/library/mac/#releasenotes/ObjectiveC/RN-TransitioningToARC/_index.html

image: Art/fno-objc-arc.png

Permalink | Leave a comment  »

]]>
http://posterous.com/images/profile/missing-user-75.png http://posterous.com/users/5ebESf1GcYud tomonaga tomonaga
Sun, 01 May 2011 02:41:00 -0700 [processing] movie http://19840618.com/processing-movie http://19840618.com/processing-movie

specify P2D on size():

size(1024, 768, P2D);

otherwise you keep getting this exception on mac:

Exception in thread "Animation Thread" java.lang.ArrayIndexOutOfBoundsException: Coordinate out of bounds!
        at sun.awt.image.IntegerInterleavedRaster.setDataElements(IntegerInterleavedRaster.java:416)
        at processing.core.PGraphicsJava2D$ImageCache.update(PGraphicsJava2D.java:959)
        at processing.core.PGraphicsJava2D.imageImpl(PGraphicsJava2D.java:834)
        at processing.core.PGraphics.image(PGraphics.java:2756)
        at processing.core.PApplet.image(PApplet.java:8637)
        at sketch_may01a.draw(sketch_may01a.java:39)
        at processing.core.PApplet.handleDraw(PApplet.java:1631)
        at processing.core.PApplet.run(PApplet.java:1530)
        at java.lang.Thread.run(Thread.java:680)

via http://processing.org/discourse/yabb2/YaBB.pl?num=1232118515

Permalink | Leave a comment  »

]]>
http://posterous.com/images/profile/missing-user-75.png http://posterous.com/users/5ebESf1GcYud tomonaga tomonaga
Fri, 29 Oct 2010 19:33:00 -0700 sys.stdout access restricted by mod_wsgi http://19840618.com/sysstdout-access-restricted-by-modwsgi http://19840618.com/sysstdout-access-restricted-by-modwsgi

work around

import sys
sys.stdout = sys.stderr

http://code.google.com/p/modwsgi/wiki/DebuggingTechniques

or (probably preferable)

WSGIRestrictStdout Off

http://blog.dscpl.com.au/2009/04/wsgi-and-printing-to-standard-output.html

Permalink | Leave a comment  »

]]>
http://posterous.com/images/profile/missing-user-75.png http://posterous.com/users/5ebESf1GcYud tomonaga tomonaga
Sat, 18 Sep 2010 10:30:00 -0700 run python in 32bit on mac os 10.6 snow leopard http://19840618.com/run-python-in-32bit-on-mac-os-106-snow-leopar http://19840618.com/run-python-in-32bit-on-mac-os-106-snow-leopar
$ defaults write com.apple.versioner.python Prefer-32-Bit -bool yes

or

$ export VERSIONER_PYTHON_PREFER_32_BIT=yes

http://www.jaharmi.com/2009/08/29/python_32_bit_execution_on_snow_leopard http://www.jaharmi.com/2009/09/01/core_graphics_bindings_on_64_bit_python_in_...

Permalink | Leave a comment  »

]]>
http://posterous.com/images/profile/missing-user-75.png http://posterous.com/users/5ebESf1GcYud tomonaga tomonaga
Sat, 11 Sep 2010 21:32:00 -0700 Cocoa/Interface Builder releases none-referenced object on NIB/XIB http://19840618.com/ib-releases-none-referenced-object-on-nib-fil http://19840618.com/ib-releases-none-referenced-object-on-nib-fil

Getting exceptions like

-[NSCFString yourAction:]: unrecognized selector sent to instance 0x751be30

Permalink | Leave a comment  »

]]>
http://posterous.com/images/profile/missing-user-75.png http://posterous.com/users/5ebESf1GcYud tomonaga tomonaga
Mon, 06 Sep 2010 19:51:00 -0700 setting a shortcut for system preferences http://19840618.com/setting-a-shortcut-for-system-preferences http://19840618.com/setting-a-shortcut-for-system-preferences

System Preferences > Keyboard > Keyboard Shortcuts

Picture_2

Permalink | Leave a comment  »

]]>
http://posterous.com/images/profile/missing-user-75.png http://posterous.com/users/5ebESf1GcYud tomonaga tomonaga
Mon, 30 Aug 2010 18:44:00 -0700 ~/Library/KeyBindings/DefaultKeyBinding.dict http://19840618.com/librarykeybindingsdefaultkeybindingdict http://19840618.com/librarykeybindingsdefaultkeybindingdict
/*
        based on http://gnufoo.org/macosx/macosx.html
        place this at ~/Library/KeyBindings/DefaultKeyBinding.dict
        “^” for Control
        “~” for Option
        “$” for Shift
        “#” for numeric keypad http://developer.apple.com/documentation/Cocoa/Conceptual/EventOverview/index.html
*/ 

{

        "^F"="moveWordForward:";
        "^B"="moveWordBackward:";
        "~f"="moveWordForward:";
        "~b"="moveWordBackward:"; 

        "^D"="deleteWordForward:";
        "^H"="deleteWordBackward:";
        "~d"="deleteWordForward:";
        "~h"="deleteWordBackward:"; 

        /* Escape should really be complete. */
        "\033"="complete:"; /* Escape */

}

Permalink | Leave a comment  »

]]>
http://posterous.com/images/profile/missing-user-75.png http://posterous.com/users/5ebESf1GcYud tomonaga tomonaga
Wed, 28 Jul 2010 07:21:00 -0700 visualize Django data models as UML http://19840618.com/visualize-django-data-models-as-uml http://19840618.com/visualize-django-data-models-as-uml

install pygraphviz via MacPorts

http://code.google.com/p/django-command-extensions/wiki/GraphModels

$ ./manage.py graph_models -a > my_project.dot
$ ./manage.py graph_models -a -g -o my_project_visualized.png
$ ./manage.py graph_models foo bar > my_project.dot

Ri_top_02

Permalink | Leave a comment  »

]]>
http://posterous.com/images/profile/missing-user-75.png http://posterous.com/users/5ebESf1GcYud tomonaga tomonaga
Mon, 26 Jul 2010 02:32:00 -0700 compile in 32bit with gcc safer on mac os x 10.6 http://19840618.com/compile-in-32bit-with-gcc-safer-on-mac-os-x-1 http://19840618.com/compile-in-32bit-with-gcc-safer-on-mac-os-x-1

for none-64-bit open source projects:

$ make clean
$ CC="gcc-4.0" CXX="g++-4.0" CFLAGS="-arch i386" LDFLAGS="-arch i386" CXXFLAGS="-arch i386" ./configure
$ make

Permalink | Leave a comment  »

]]>
http://posterous.com/images/profile/missing-user-75.png http://posterous.com/users/5ebESf1GcYud tomonaga tomonaga
Mon, 26 Jul 2010 02:22:00 -0700 [NSView viewWithTag:] http://19840618.com/nsview-viewwithtag http://19840618.com/nsview-viewwithtag

viewWithTag:

Returns the receiver’s nearest descendant (including itself) with a specific tag, or nil if no subview has that tag.

- (id)viewWithTag:(NSInteger)aTag

 

Permalink | Leave a comment  »

]]>
http://posterous.com/images/profile/missing-user-75.png http://posterous.com/users/5ebESf1GcYud tomonaga tomonaga
Sun, 18 Jul 2010 10:01:00 -0700 what to do & install first for a new mac http://19840618.com/what-to-do-first-for-a-new-mac http://19840618.com/what-to-do-first-for-a-new-mac

install applications

system preference

  • keyboard > modifier key > change Caps Lock to Control
  • keyboard > keyboard shortcuts > add:
    app: "All Applications" / title: "System Preferences" / shortcut: Command + Shift + Comma
  • mouse > set Tracking faster, activate Secondary Button (ie. Right Click)
  • appearance > Click in the scroll bar to: > Jump to the spot that's clicked
  • appearance > check Double-click a window's title bar to minimize
  • expose & spaces > activate corner shortcut
  • (optional) sharing > File / Web / Screen Sharing, Remote Login
  • (optional) network > set fixed IP adress
  • (japanese) keyboard > keyboard shortcuts > set Spotlight to Command+Shift+Space
  • (japanese) language > input method > add Kotoeri Romaji / Kotoeri preference: Windows-like input style

other configuration

transfer from old environment

  • copy HOME>Library>Preferences and HOME>Library>Application Supports

Permalink | Leave a comment  »

]]>
http://posterous.com/images/profile/missing-user-75.png http://posterous.com/users/5ebESf1GcYud tomonaga tomonaga
Sun, 18 Jul 2010 09:46:00 -0700 download old versions of xcode http://19840618.com/download-old-versions-of-xcode http://19840618.com/download-old-versions-of-xcode

http://iphonesdkdev.blogspot.com/2010/04/old-versions-of-iphone-sdk.html

Permalink | Leave a comment  »

]]>
http://posterous.com/images/profile/missing-user-75.png http://posterous.com/users/5ebESf1GcYud tomonaga tomonaga
Sun, 18 Jul 2010 09:17:00 -0700 calling C++ global function from Python ctypes http://19840618.com/calling-c-global-function-from-python-ctypes http://19840618.com/calling-c-global-function-from-python-ctypes
#ifdef __cplusplus
extern "C" {
#endif

void audio_setup() {
        // c++ code
}

#ifdef __cplusplus
}
#endif

Permalink | Leave a comment  »

]]>
http://posterous.com/images/profile/missing-user-75.png http://posterous.com/users/5ebESf1GcYud tomonaga tomonaga
Sun, 18 Jul 2010 09:16:00 -0700 'enctype' for form upload field http://19840618.com/enctype-for-form-upload-field http://19840618.com/enctype-for-form-upload-field

enctype="multipart/form-data" attribute is required for <form> tag

http://docs.djangoproject.com/en/dev/topics/http/file-uploads/

Permalink | Leave a comment  »

]]>
http://posterous.com/images/profile/missing-user-75.png http://posterous.com/users/5ebESf1GcYud tomonaga tomonaga
Sun, 18 Jul 2010 09:15:00 -0700 using VBO with PyOpenGL http://19840618.com/using-vbo-with-pyopengl http://19840618.com/using-vbo-with-pyopengl
### to prepare ###

arr = [(float(x)/(size-1),float(y)/(size-1))
            for x in xrange(size)
            for y in xrange(size)]
arr = np.require(arr, 'f')
self.vbo = OpenGL.arrays.vbo.VBO(arr , 'GL_STATIC_DRAW')

### to use ###

self.vbo.bind()
glEnableClientState(GL_VERTEX_ARRAY)
glEnableClientState(GL_TEXTURE_COORD_ARRAY)
glTexCoordPointer(2, GL_FLOAT, 0, None)
glVertexPointer(2, GL_FLOAT, 0, None)
glDrawArrays(GL_POINTS, 0, N_PARTICLE)
glDisableClientState(GL_VERTEX_ARRAY)
glDisableClientState(GL_TEXTURE_COORD_ARRAY)
self.vbo.unbind()

* The last argument for glVertexPointer should be None, not 0.

Permalink | Leave a comment  »

]]>
http://posterous.com/images/profile/missing-user-75.png http://posterous.com/users/5ebESf1GcYud tomonaga tomonaga
Sun, 18 Jul 2010 09:09:00 -0700 creating disk image for mac os x 10.5 and 10.6 http://19840618.com/creating-disk-image-for-mac-os-x-105-and-106 http://19840618.com/creating-disk-image-for-mac-os-x-105-and-106

* do this on 10.5, otherwise the custom icon size / background will be lost.

useful Makefile to build a disk image: http://el-tramo.be/guides/fancy-dmg

update its line 67:

WC_DEV=`hdiutil info | grep "wc" | grep "/dev/" | awk '{print $$1}'` && hdiutil detach $$WC_DEV -quiet -force

Permalink | Leave a comment  »

]]>
http://posterous.com/images/profile/missing-user-75.png http://posterous.com/users/5ebESf1GcYud tomonaga tomonaga
Sun, 18 Jul 2010 09:08:00 -0700 adding custom property to CAAnimation http://19840618.com/adding-custom-property-to-caanimation http://19840618.com/adding-custom-property-to-caanimation

* override copyWithZone:

@interface MyLayerAnimation : CABasicAnimation
{
    MyItemLayer *relatedLayer;
}
@property (assign) __weak MyItemLayer *relatedLayer;

@end


@implementation MyLayerAnimation

@synthesize relatedLayer;

- (id)copyWithZone:(NSZone *)zone
{
    MyLayerAnimation *newObj = [super copyWithZone:zone];
    newObj.relatedLayer = self.relatedLayer;
    return newObj;
}

@end

Permalink | Leave a comment  »

]]>
http://posterous.com/images/profile/missing-user-75.png http://posterous.com/users/5ebESf1GcYud tomonaga tomonaga
Sun, 18 Jul 2010 09:06:00 -0700 midi with python on mac os x 10.6 http://19840618.com/midi-with-python-on-mac-os-x-106 http://19840618.com/midi-with-python-on-mac-os-x-106

set python in 32bit mode:

$ defaults write com.apple.versioner.python Prefer-32-Bit -bool yes

install http://trac2.assembla.com/pkaudio/wiki/pyrtmidi

Permalink | Leave a comment  »

]]>
http://posterous.com/images/profile/missing-user-75.png http://posterous.com/users/5ebESf1GcYud tomonaga tomonaga
Sun, 18 Jul 2010 09:04:00 -0700 smallest CoreAudio code to grab audio out on iPhone http://19840618.com/minimal-code-to-grab-audio-out-on-iphone http://19840618.com/minimal-code-to-grab-audio-out-on-iphone

will generate & play realtime white noise on iphone.

MyAudio.h

#import 

#define MY_AUDIO_BUFFERS_NUM 4
#define MY_AUDIO_BUFFER_FRAMES 256
#define MY_AUDIO_BUFFER_SIZE (MY_AUDIO_BUFFER_FRAMES * 2 * 2)

@interface MyAudio : NSObject {
    AudioQueueRef queueObject;
    AudioQueueBufferRef audioBuffers[MY_AUDIO_BUFFERS_NUM];
    AudioStreamBasicDescription audioFormat;
}

- (IBAction)setupAudio:(id)sender;
- (IBAction)teardownAudio:(id)sender;

@end

MyAudio.m

#import "MyAudio.h"

@interface MyAudio ()
- (void)playbackCallbackWithAudioQueue:(AudioQueueRef)inAudioQueue
                                buffer:(AudioQueueBufferRef)bufferReference;
@end

static void PlaybackCallback (
                              void *inUserData,
                              AudioQueueRef inAudioQueue,
                              AudioQueueBufferRef bufferReference
                              )
{
    [(MyAudio *)inUserData playbackCallbackWithAudioQueue:inAudioQueue
                                                   buffer:bufferReference];

}

@implementation MyAudio

- (void)playbackCallbackWithAudioQueue:(AudioQueueRef)inAudioQueue
                                buffer:(AudioQueueBufferRef)bufferReference;
{
    NSUInteger numBytes = MY_AUDIO_BUFFER_SIZE;
    NSUInteger bytesPerFrame = audioFormat.mBytesPerFrame;
    NSUInteger channlesPerFrame = audioFormat.mChannelsPerFrame;
    NSUInteger bytesPerSample = bytesPerFrame/channlesPerFrame;
    NSUInteger numFrames = numBytes/bytesPerFrame;
    NSUInteger i=0;

    while (imAudioData + dstAddr) = (AudioSampleType)(rand() / (float)RAND_MAX * 10);
        *(AudioSampleType *)(bufferReference->mAudioData + dstAddr + bytesPerSample) = (AudioSampleType)(rand() / (float)RAND_MAX * 10);
        i++;
    }

    bufferReference->mAudioDataByteSize = numBytes;
    AudioQueueEnqueueBuffer (inAudioQueue,
                             bufferReference,
                             0,
                             NULL);
}

- (IBAction)setupAudio:(id)sender
{
    audioFormat.mFormatID = 1819304813;
    audioFormat.mFormatFlags = 14;
    audioFormat.mSampleRate = 44100.0;
    audioFormat.mChannelsPerFrame = 2;
    audioFormat.mFramesPerPacket = 1;
    audioFormat.mBytesPerFrame =  4;
    audioFormat.mBytesPerPacket = 4;
    audioFormat.mBitsPerChannel = 16;
    audioFormat.mReserved = 0;
    OSStatus ret =  AudioQueueNewOutput (
                         &audioFormat,
                         PlaybackCallback,
                         self, 
                         CFRunLoopGetCurrent (),
                         kCFRunLoopCommonModes,
                         0, // run loop flags
                         &queueObject);

    assert(ret == noErr);
    assert(queueObject != NULL);
    assert(audioFormat.mChannelsPerFrame==2);

    Float32 gain = 1.0;
    AudioQueueSetParameter (queueObject,
                            kAudioQueueParam_Volume,
                            gain);

    NSUInteger bufferIndex;
    for (bufferIndex = 0; bufferIndex < MY_AUDIO_BUFFERS_NUM; ++bufferIndex) {
 AudioQueueAllocateBuffer (queueObject,
                                  MY_AUDIO_BUFFER_SIZE,
                                  &audioBuffers[bufferIndex]);
        audioBuffers[bufferIndex]->mAudioDataByteSize = MY_AUDIO_BUFFER_SIZE;
        AudioQueueEnqueueBuffer(queueObject, audioBuffers[bufferIndex], 0, NULL);
    }

    UInt32 sessionCategory = kAudioSessionCategory_MediaPlayback;
    AudioSessionSetProperty(kAudioSessionProperty_AudioCategory,
                            sizeof (sessionCategory),
                            &sessionCategory);
    AudioSessionSetActive(true);

    ret =  AudioQueueStart (queueObject,
                            NULL);
    assert(ret == noErr);
}

- (void)teardownAudio
{
    AudioQueueStop (queueObject, YES);
    AudioQueueDispose (queueObject, YES);
}

@end

Permalink | Leave a comment  »

]]>
http://posterous.com/images/profile/missing-user-75.png http://posterous.com/users/5ebESf1GcYud tomonaga tomonaga