Skip to content

Instantly share code, notes, and snippets.

class Post < ActiveRecord::Base
default_scope :order => 'created_at DESC'
end
@panupan
panupan / test.rb
Created February 27, 2011 21:59
Test
class Foobar
def foo
puts 'hello world'
end
end
@panupan
panupan / gist:1023808
Created June 13, 2011 21:49 — forked from chadmoone/gist:1023734
Bug is not present when using store.loadRecords instead of Fixtures
// ==========================================================================
// Project: RecordBug
// Copyright: @2011 My Company, Inc.
// ==========================================================================
/*globals RecordBug */
RecordBug = SC.Application.create({
store: SC.Store.create().from(SC.Record.fixtures)
});
@panupan
panupan / VBox.h
Created September 23, 2011 23:18
Cocoa VBox
//
// VBox.h
// VBox
//
// Created by Panupan Sriautharawong on 9/23/11.
// Copyright 2011 Panupan.com. All rights reserved.
//
@interface WILLVBox : NSView {
NSColor *backgroundColor;
@panupan
panupan / s3mirror.sh
Created October 25, 2011 20:34
Mirror all Amazon S3 buckets with daily cron script using s3cmd
#!/bin/bash
BACKUP_DIR='/backups/S3 Mirror/'
BUCKETS=$(s3cmd ls | grep s3 | awk '{ print $3 }')
for i in $BUCKETS; do
CURRENT_DIR=$BACKUP_DIR${i//s3:\/\//}/
echo Mirroring $i to $CURRENT_DIR
mkdir -p "$CURRENT_DIR"
s3cmd sync --verbose --no-check-md5 --recursive --no-delete-removed $i "$CURRENT_DIR"
@panupan
panupan / gist:1354258
Created November 10, 2011 06:24
Cocoa / Obj-C - return the number of running application instances
- (int)instanceCount {
int i = 0;
NSString *appName = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleName"];
for (NSRunningApplication *app in [[NSWorkspace sharedWorkspace] runningApplications]) {
if ([appName isEqualToString:[app localizedName]]) i++;
}
return i;
}
@panupan
panupan / gist:3440412
Created August 23, 2012 19:05
NSView post processing
CGContextSetBlendMode([[NSGraphicsContext currentContext] graphicsPort], kCGBlendModeScreen);
CGContextSetRGBFillColor ([[NSGraphicsContext currentContext] graphicsPort], 1, 1, 1, .8);
CGContextFillRect([[NSGraphicsContext currentContext] graphicsPort], self.backgroundRect);
CGContextSetBlendMode([[NSGraphicsContext currentContext] graphicsPort], kCGBlendModeColor);
CGContextSetRGBFillColor ([[NSGraphicsContext currentContext] graphicsPort], 1, 1, 1, 1);
CGContextFillRect([[NSGraphicsContext currentContext] graphicsPort], self.backgroundRect);
@panupan
panupan / NSImage+Grayscale.h
Created August 24, 2012 16:38
NSImage Grayscale transform with Core Animation CIFilter
//
// NSImage+Grayscale.h
//
// Created by Panupan Sriautharawong on 8/7/12.
//
//
#import <Cocoa/Cocoa.h>
@interface NSImage (Grayscale)
@panupan
panupan / videocapturefps.m
Created September 4, 2012 00:28
iOS Controlling Video Capture FPS rate
- (void)captureOutput:(AVCaptureOutput *)captureOutput
didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer
fromConnection:(AVCaptureConnection *)connection
{
if (connection.isVideoMinFrameDurationSupported && connection.videoMinFrameDuration.timescale != FPS) {
connection.videoMinFrameDuration = CMTimeMake(1, FPS);
}
if (connection.isVideoMaxFrameDurationSupported && connection.videoMaxFrameDuration.timescale != FPS) {
connection.videoMaxFrameDuration = CMTimeMake(1, FPS);
@panupan
panupan / respondersview.h
Created September 28, 2011 17:51
NSViewController responder chain integration
//
// RespondersView.h
// RespondersView
//
// Created by Panupan Sriautharawong on 9/13/11.
// Copyright 2011 Panupan.com. All rights reserved.
//
#import <Cocoa/Cocoa.h>