This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class UserRenameAvatarToProfileRemoveAAddB < ActiveRecord::Migration | |
# you may want to change these | |
AttachmentColumns = [["file_name", :string], ["content_type", :string], ["file_size", :integer]] | |
# make sure this matches your setup, also have a look in the rename and remove methods | |
AttachmentPath = Rails.root.join("public", "system") | |
def self.rename_attachment(table, old, new) | |
AttachmentColumns.each do |suffix, type| | |
rename_column table, "#{old}_#{suffix}", "#{new}_#{suffix}" | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Output select query as insert statements | |
# | |
# Ex: insert all users from database1 into database2 but replace password with "dummy" | |
# ./mysqlselectdump username database1 "SELECT id, name, \"dummy\" as password FROM users" users password | mysql -u username -ppassword database2 | |
USERNAME="$1" | |
DATABASE="$2" | |
QUERY="$3" | |
INSERTTABLE="$4" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# requires that you use "set :deploy_via, :remote_cache" in deploy.rb | |
while read oldrev newrev ref | |
do | |
if [ "$ref" = "refs/heads/master" ] ; then | |
echo "Master branch pushed, deploying to staging" | |
# seams to be set to "." for hooks, unset to make things more normal | |
unset GIT_DIR | |
# deploy path, where "current", "releases", "shared" etc are |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# WARNING: don't just use this without testing! | |
# This is not a database migration but i think it's quite convenient to do as a migration | |
# multiple styles has not been tested but should work | |
class ChangeAttachmentPaths < ActiveRecord::Migration | |
AttachmentPath = Rails.root.join("public", "system") | |
def self.paperclip_change_path(table, column, old_opt, new_opt) | |
model = table.to_s.classify.constantize |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// a bit hackish way of merging two wav files, assumes raw samples. | |
#import <Foundation/Foundation.h> | |
#define RIFF_ID 0x52494646 // "RIFF" | |
#define RIFF_FMT_ID 0x666d7420 // "fmt " | |
#define RIFF_DATA_ID 0x64617461 // "data" | |
typedef struct riffChunkHeader { | |
UInt32 rsc_id; // big endian |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env awk -f | |
# print class and instance methods declarations from implementation | |
# Usage: ./printmethods.awk class.m or awk -f printmethods.awk class.m | |
/^[[:space:]]*@implementation/ { | |
implementation = 1; | |
} | |
/^[[:space:]]*@end/ { | |
implementation = 0; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
function check_file() { | |
echo $1 | |
awk ' | |
/.*/ { | |
if (inblock > 0) { | |
collect = collect $0 "\n"; | |
} | |
line = line + 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static NSUInteger binary_search_range_index(NSUInteger *positions, | |
NSUInteger len, | |
NSUInteger n) { | |
NSInteger current = len / 2; | |
NSUInteger delta = len / 2; | |
while (!(n >= positions[current] && | |
(current == len-1 || n < positions[current+1]))) { | |
delta = delta / 2; | |
if (delta == 0) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@interface NSObject (classNameOfPropetyName) | |
- (Class)classOfPropetyName:(NSString *)propertyName; | |
@end | |
@implementation NSObject (classNameOfPropetyName) | |
- (Class)classOfPropetyName:(NSString *)propertyName { | |
static NSRegularExpression *re = nil; | |
static dispatch_once_t onceToken; | |
dispatch_once(&onceToken, ^{ | |
// T@"NSString",&,N,Vtest | |
re = [[NSRegularExpression alloc] initWithPattern:@"@\"([^\"]*)\"" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@interface NSString (stringByResolvingCanonicalPath) | |
- (NSString *)stringByResolvingCanonicalPath; | |
@end | |
@implementation NSString (stringByResolvingCanonicalPath) | |
- (NSString *)stringByResolvingCanonicalPath { | |
FSRef fsRef; | |
if (FSPathMakeRef((UInt8 const *)[self UTF8String], &fsRef, NULL) != 0) { | |
return nil; |
OlderNewer