Skip to content

Instantly share code, notes, and snippets.

@venj
venj / vcext.snippet
Created January 27, 2015 13:24
Code Snippet for visual studio to generate class extension template. Trigger: vcext<TAB><TAB>
<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>Class Extension</Title>
<Shortcut>vcext</Shortcut>
<Description>Add Method To Existing Class With Extension</Description>
<Author>Venj Chu</Author>
<SnippetTypes>
<SnippetType>Expansion</SnippetType>
@venj
venj / string_extension.cs
Created January 27, 2015 12:41
Class extension syntax for C#
namespace System
{
public static class StringExtension
{
public static string TimesMe(this String str, int times)
{
StringBuilder sb = new StringBuilder();
for (int i = 0; i < times; i++)
{
@venj
venj / toupiao.rb
Last active August 29, 2015 14:11
#!/usr/bin/env ruby
require "open-uri"
ARGV[0].to_i.times {|i| open "http://www.sh-anfang.org/expert/expert.asp?tp=5&id=5"; puts "已刷#{i + 1}票。" }
puts "完成"
# One-liner:
# ruby -ropen-uri -e "2.times {|i| open 'http://www.sh-anfang.org/expert/expert.asp?tp=5&id=5'; puts \"已刷#{i + 1}票。\" };puts '完成' "
#!/usr/bin/env xcrun swift
import Foundation
if NSFoundationVersionNumber < 1139.1 {
println("You need Xcode6-DP5 and up to run this script")
exit(1)
}
let args = Process.arguments
@venj
venj / UIColorExtra.swift
Last active August 29, 2015 14:04
A UIColor Extension to parse Hex string(for CSS and for KML) to color. Code works for Xcode 6 Beta 5. Based on https://github.com/yeahdongcn/UIColor-Hex-Swift/blob/master/UIColorExtension.swift
import UIKit
extension UIColor {
convenience init(kmlColorString:String) {
var scanner = NSScanner(string:kmlColorString)
var color:UInt32 = 0;
scanner.scanHexInt(&color)
let mask:UInt32 = 0x000000FF
var a = color >> 24 & mask
@venj
venj / down.rb
Last active August 29, 2015 14:03
#!/usr/bin/env ruby
# Will download to Files in current directory.
# To download:
# ruby down.rb
require "open-uri"
require "fileutils"
include FileUtils
USER = "data_public"
http://devstreaming.apple.com/videos/wwdc/2014/403xxksrj0qs8c0/403/403_hd_intermediate_swift.mov?dl=1
http://devstreaming.apple.com/videos/wwdc/2014/419xxli6f60a6bs/419/419_hd_advanced_graphics_and_animation_performance.mov?dl=1
http://devstreaming.apple.com/videos/wwdc/2014/101xx36lr6smzjo/101/101_hd.mov?dl=1
http://devstreaming.apple.com/videos/wwdc/2014/236xxwk3fv82sx2/236/236_hd_building_interruptible_and_responsive_interactions.mov?dl=1
http://devstreaming.apple.com/videos/wwdc/2014/306xxjtg7uz13v0/306/306_hd_javascript_for_automation.mov?dl=1
http://devstreaming.apple.com/videos/wwdc/2014/404xxdxsstkaqjb/404/404_hd_advanced_swift.mov?dl=1
http://devstreaming.apple.com/videos/wwdc/2014/701xx8n8ca3aq4j/701/701_hd_designing_accessories_for_ios_and_os_x.mov?dl=1
http://devstreaming.apple.com/videos/wwdc/2014/224xxxlsvigdoc0/224/224_hd_core_os_ios_application_architectural_patterns.mov?dl=1
http://devstreaming.apple.com/videos/wwdc/2014/717xxux5eg6f9v4/717/717_hd_kids_and_apps.mov?dl=1
http://devstreaming.ap
#!/bin/sh
if [ $UID -ne 0 ]; then
echo "\033[31mSuperuser privileges are required to run this script.\033[0m"
echo "e.g. \"\033[33msudo\033[0m $0\""
exit 1
fi
driver=AX88179_178A.kext
driver_path=/Library/Extensions/$driver
#!/usr/bin/env ruby
# Rotate video files.
require 'shellwords'
require 'colorize'
TMPFILE = "/tmp/ffprobe_out.txt"
IMAGES = ["mjpeg", "jpg", "jpeg", "png", "gif"]
if (`which ffmpeg` == "")
puts "You need ffmpeg to use this command."
#!/usr/bin/env ruby
# encoding = UTF-8
# 模拟导航数据转换GPS坐标算法
# 接受一个参数,指定模拟导航数据文件的名字
path = ARGV[0]
open("result.txt", "w+") do |f|
open(path).each_line do |line|
x, y = line.sub("[", "").sub("]", "").split(",").map {|i|