Skip to content

Instantly share code, notes, and snippets.

@venj
venj / apod.sh
Created May 10, 2012 01:59
Download NASA Astronomy Picture Of Day media. (Bash version)
#!/bin/bash
# Constants
TMPDIR=/tmp/apod
LISTFILE=$TMPDIR/list.html
REMOTEPREFIX=http://antwrp.gsfc.nasa.gov/apod/
# Functions
function parse_page() {
printf "Downloading photo page %s...\n" $1
@venj
venj / anyduplicate.rb
Created May 11, 2012 06:25
find duplicate city name for me.
#!/usr/bin/ruby
#encoding=utf8
cities = {}
open("/Users/venj/Desktop/city.txt").each_line do |l|
city = l.split("=").last
if cities[city].nil?
cities[city] = 0
else
cities[city] += 1
@venj
venj / f4v_to_m4v.rb
Created May 14, 2012 05:22
Remux f4v to m4v.
#!/usr/bin/env ruby
Dir["*.f4v"].each do |file|
name = File.basename file, ".f4v"
system("ffmpeg -i '#{file}' -acodec copy -vcodec copy '#{name}.m4v'")
end
@venj
venj / color.sh
Created May 14, 2012 07:25
Color in terminal
#!/bin/bash
# colors.sh - Print out all the different ECMA color-mod combos
#
# 2008 - Mike Golvach - [email protected]
#
# Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License
#
declare -a color_array
@venj
venj / remux.rb
Created May 20, 2012 06:56
The real deal remux script that can remux videos with M4V compatible video stream. Audio stream will be encoded to 192kbps aac if it is not m4v compatible audio.
#!/usr/bin/env ruby
# Remux MP4/H264 videos (mkv, avi, etc.) to m4v.
TMPFILE = "/tmp/ffprobe_out.txt"
VIDEO_CONTAINER = ["mkv", "f4v", "avi", "divx", "ts"]
VCODECS = ["mpeg4", "h264"]
ACODECS = ["aac"]
if (`which ffmpeg` == "")
puts "You need ffmpeg to use this command."
@venj
venj / preprocess.rb
Created May 21, 2012 05:38
batch convert images for appstore for my project.
#!/usr/bin/env ruby
require "fileutils"
include FileUtils
p = "processed"
mkdir "processed" unless File.exists?(p)
Dir["*.png"].each do |f|
puts "Processing #{f}."
name = File.basename(f).split('.')[0]
@venj
venj / calc.vb
Created May 29, 2012 00:43
old code for the lab
Attribute VB_Name = "包合常数自动计算脚本"
'
' 作者: venj
' 日期: 2007年01月06日
' 版本: 0.2.0 Update 1
'
' 用途: 环糊精包合常数自动计算脚本
'
' ChangeLog:
@venj
venj / com.yourcompany.autossh.plist
Created May 30, 2012 14:39
Put following gist to ~/Library/LaunchAgents, and then run: launchctl load /Users/your_name/Library/LaunchAgents/com.yourcompany.autossh.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>OnDemand</key>
<false/>
<key>KeepAlive</key>
<true/>
@venj
venj / fix_size_image.rb
Created June 9, 2012 06:02
convert images to fixed width images
#!/usr/bin/env ruby
TARGET_WIDTH = 1000.0
Dir["*.jpg"].each do |f|
fileinfo = `convert #{f} -print "%wx%h" /dev/null`
width, height = fileinfo.split("x").collect(&:to_i)
height *= (TARGET_WIDTH / width)
width = TARGET_WIDTH
print "Processing #{f}..."
@venj
venj / geocode.m
Created July 5, 2012 05:42
iOS 5 Geocode question.
/*
用iOS 5的GeoCoder API,反向解析经纬度。代码简略如下:
*/
CGFloat lat = 30.0; CGFloat lng = 120.0;
CLGeocoder *coder = [[CLGeocoder alloc] init];
CLLocation *mapLocation = [[CLLocation alloc] initWithLatitude:lat longitude:lng];
[coder reverseGeocodeLocation:mapLocation completionHandler:^(NSArray *placemarks, NSError *error) {