Skip to content

Instantly share code, notes, and snippets.

View hSATAC's full-sized avatar
🐈
Cataholic

Ash Wu hSATAC

🐈
Cataholic
View GitHub Profile
@hSATAC
hSATAC / gist:2418763
Created April 19, 2012 05:14
delete Redmine duplicated attachments
def del_dup
for a in Attachment.all
dup = Attachment.find(:all, :conditions=>{:filename => a.filename, :filesize=>a.filesize})
if dup.count > 1
puts "Duplicated Attachment found! Start purging..."
puts "item # #{a.id} #{a.filename} (#{a.filesize}) got #{dup.count} duplicated items."
for as in dup[1..-1]
puts "Deleting #{as.id}..."
as.delete_from_disk
as.destroy
@hSATAC
hSATAC / git versioner
Created May 25, 2012 04:35 — forked from Abizern/git versioner
Xcode build script that adds the commit sha to the CFBundleVersion
#!/usr/bin/env ruby
# Xcode auto-versioning script for Subversion by Axel Andersson
# Updated for git by Marcus S. Zarra and Matt Long
# Converted to ruby by Abizer Nasir
# Appends the git sha to the version number set in Xcode.
# see http://www.stompy.org/2008/08/14/xcode-and-git-another-build-script/ for more details
# These are the common places where git is installed.
# Change this if your path isn't here
@hSATAC
hSATAC / gist:2785809
Created May 25, 2012 04:42
set git rev as xcode bundle version
#!/usr/bin/env ruby
plist = "/Users/cat/projects/proj/proj-Info.plist"
version = `git rev-parse --short HEAD`
`/usr/libexec/Plistbuddy -c "Set CFBundleVersion #{version}" #{plist}`
@hSATAC
hSATAC / gist:2880516
Created June 6, 2012 07:49
aws ec2 dynamic dns for route 53 (CNAME)
#!/bin/sh
# Setup dynamic dns on Route 53 for aws ec2 (CNAME)
#
# Modified from Johan Lindh's script
#
# Script requirements:
#
# wget
# grep
@hSATAC
hSATAC / ec2_hosts.rb
Created June 6, 2012 10:16
generate ec2 /etc/hosts
#!/usr/bin/env ruby
# coding: utf-8
require 'rubygems'
require 'aws-sdk'
config = {:access_key_id => '',
:secret_access_key => ''}
AWS.config(config)
ec2 = AWS::EC2.new
ec2 = ec2.regions['ap-northeast-1']
@hSATAC
hSATAC / hostname.rb
Created June 7, 2012 07:48
aws ec2 set hostname by tag name
#!/usr/bin/env ruby
require 'rubygems'
require 'aws-sdk'
instance_id = `wget "http://169.254.169.254/latest/meta-data/instance-id" -o /dev/null -O /dev/stdout`
config = {:access_key_id => '',
:secret_access_key => ''}
AWS.config(config)
ec2 = AWS::EC2.new
ec2 = ec2.regions['ap-northeast-1']
/*
example of c equivalent to php
<?php
// Create the keypair
$res=openssl_pkey_new();
// Get private key
openssl_pkey_export($res, $privkey);
// Get public key
@hSATAC
hSATAC / gist:3096221
Created July 12, 2012 06:15
turn image into datauri
Display local UIImage on UIWebview
[[NSBundle mainBundle] bundleURL]
[[NSBundle mainBundle] URLForResource:@"myimage" withExtension:@"png"]
#import "NSString+DataURI.h"
#import "NSData+Base64.h"
...
-(void)webViewDidFinishLoad:(UIWebView *)webView
@hSATAC
hSATAC / mountain-lion-brew-setup.markdown
Created July 31, 2012 09:20 — forked from myobie/mountain-lion-brew-setup.markdown
Get Mountain Lion and Homebrew to Be Happy

Get Mountain Lion and Homebrew to Be Happy

1) Install XCode 4.4 into /Applications

Get it from the App Store.

2) Install Command Line Tools

In XCode's Preferences > Downloads you can install command line tools.

@hSATAC
hSATAC / gist:3246217
Created August 3, 2012 09:17
Check git branch been merged or not
#!/usr/bin/env ruby
require 'rubygems'
require 'active_support'
merged = `cd /home/m/git/repositories/miiicasa.git && git branch --merged master | grep -v master`
not_merged_cmd = 'cd /home/m/git/repositories/miiicasa.git && git branch | grep -v master | grep -v support | grep -v qa'
for line in merged.split("\n")
not_merged_cmd += '| grep -v ' + line
end
puts "This is a regular check of miiiCasa.git branches\n"