Skip to content

Instantly share code, notes, and snippets.

@venj
venj / logroll.sh
Created May 21, 2011 00:57
A simple logroll for my vps
# Add this script to root's cron
# Do it every sunday.
# 0 0 * * 0 /path/to/logroll.sh
function roll_log {
if [ $(ls -s $1 | cut -d' ' -f1) -gt '10240' ]; then
ts=$(date +%s)
mv $1 ${1}.$ts
if [ $? -ne 0 ];then
exit 1
fi
#!/bin/sh
# Change this line to the URI path of the xcode DMG file.
# XCode 3.2.5
#XCODE_PATH="/ios/ios_sdk_4.2__final/xcode_3.2.5_and_ios_sdk_4.2_final.dmg"
# XCode 4
#XCODE_PATH="/Developer_Tools/xcode_4_and_ios_sdk_4.3__final/xcode_4_and_ios_sdk_4.3__final.dmg"
@venj
venj / brewcleanup.sh
Created May 22, 2011 09:24
clean up brew old packages. There will be some warnings and errors, just ignore them.
#!/bin/bash
for pack_name in $(ls $(brew --prefix)/Cellar);do
brew cleanup $pack_name 2> /dev/null
done
@venj
venj / my.sh
Created May 22, 2011 09:26
my personal system management scripts system. This is the main script. All the command scripts are located in /usr/local/bin/myscripts .
#!/bin/sh
myscript_dir=/usr/local/bin/myscripts
if [ $# -lt 1 ]; then
echo "Usage: $(basename $0) command_name [options]"
echo "Help: "
echo "\t list (l) -- show all available commands"
echo "\t - ll -- show all available commands, long format"
echo "\t - la -- show all available commands, full format"
@venj
venj / down_wwdc_keynote.rb
Created June 7, 2011 15:02
Download WWDC '11 Keynote to your hard disk
#!/usr/bin/env ruby
require 'open-uri'
if ["--help", "help", "-h"].include?(ARGV[0]) || ARGV.size < 1
puts "Usage: #{File.basename __FILE__} ( 720p | 540p | 540i | 360p | 360i | 360is | 224p )"
exit 0
end
size_hash = {"720p" => "4540", "540p" => "2540", "540i" => "1840", "360p" => "1240", "360i" => "0640", "360is" => "0440", "224p" => "0240"}
video_size = size_hash[ARGV[0]]
@venj
venj / gen_db.rb
Created July 4, 2011 03:07
gen database file for hsk app
#!/usr/bin/env ruby
require "sqlite3"
dbfile = "data.sqlite3"
File.unlink dbfile if File.exists? dbfile
db = SQLite3::Database.new dbfile
db.execute("create table `entries` (id integer primary key autoincrement, question string, choice1 string, choice2 string, answer string);")
infile = open "dd.txt", 'r'
@venj
venj / AppDelegate.m
Created August 15, 2011 04:58
One line Fanfou Mac client
#import "Fanfou_For_MacAppDelegate.h"
#import <Webkit/WebKit.h>
@implementation Fanfou_For_MacAppDelegate
@synthesize window;
@synthesize webView;
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
@venj
venj / rename.rb
Created August 16, 2011 13:48
Extract and Rename rar files downloaded from Wow Ebooks
#!/usr/bin/env ruby
require "fileutils"
include FileUtils
#
# Now you can fire up the command like this:
# ./rename.rb New.Riders.Flexible.Web.Design.Dec.2008.rar Flexible Web Design
#
# if there's any special characters in the REAL file name,
# escape them to prevent the shell to parse it.
@venj
venj / iOS System Fonts.txt
Created August 21, 2011 08:02
iOS System Fonts
American Typewriter:
AmericanTypewriter
AmericanTypewriter-Bold
Apple Color Emoji:
AppleColorEmoji
AppleGothic:
AppleGothic
@venj
venj / split.rb
Created August 25, 2011 13:06
Split a image into two halves.
#!/usr/bin/env ruby
require "fileutils"
(puts "Usage: #{File.basename $0} widthxheight"; exit 0) if ARGV.size != 1
width, height = ARGV[0].split("x").collect(&:to_i)
(puts "Please enter a valid size."; exit 0) if ((width.to_i == 0) or (height.to_i == 0))
half_width = width / 2
FileUtils.cd("images") do
Dir['**/*'].each do |f|