Skip to content

Instantly share code, notes, and snippets.

View forresty's full-sized avatar

Feng Ye forresty

View GitHub Profile
#!/usr/bin/ruby
last = 1
def num1(num)
result = 0
while num > 0
if num % 10 == 1
result += 1
end
package se.fnord.android.layout;
import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
/**
* ViewGroup that arranges child views in a similar way to text, with them laid
* out one line at a time and "wrapping" to the next line as needed.
var httpUrl = 'http://www.google.com/reader';
var httpsUrl = 'https://www.google.com/reader';
if (0 === tab.url.indexOf(httpUrl)) {
chrome.tabs.update(tab.id, {url: tab.url.replace(httpUrl, httpsUrl)});
}
<!DOCTYPE html>
<html>
<head>
<script>
function checkForHttpAccessToGoogleReader(tabId, changeInfo, tab) {
var httpUrl = 'http://www.google.com/reader';
var httpsUrl = 'https://www.google.com/reader';
if (0 === tab.url.indexOf(httpUrl)) {
chrome.tabs.update(tab.id, {url: tab.url.replace(httpUrl, httpsUrl)});
}
@forresty
forresty / gist:747358
Created December 19, 2010 14:20
MTStatusBarOverlay Test Case
- (void)viewDidLoad {
[super viewDidLoad];
MTStatusBarOverlay *overlay = [MTStatusBarOverlay sharedInstance];
overlay.animation = MTStatusBarOverlayAnimationShrink;
[overlay showWithMessage:@"Loading..."];
[NSThread detachNewThreadSelector:@selector(loadFromServer) toTarget:self withObject:nil];
}
@forresty
forresty / broken_math.rb
Created August 12, 2011 13:52
Break the math!
#!/usr/bin/env ruby
class Fixnum
alias :original_add :+
def +(another)
original_add(another).original_add(1)
end
end
puts "1 + 1 = #{1+1}"
@forresty
forresty / download_all_tasks.rb
Created October 11, 2011 03:25
A browser script to automatically parse all lixian.vip.xunlei.com file names and URLs
#!/usr/bin/env ruby
require "yaml"
# make sure you have dump cookies to xunlei-cookies.txt
YAML.load_file("all_files.yml").each do |file|
cmd = "wget --load-cookies=xunlei-cookies.txt '#{file[:url]}' -c -O '#{file[:name]}'"
system(cmd)
end
@forresty
forresty / video-list.txt
Created October 16, 2011 14:35
Stanford ML Class Video Links
http://s3.amazonaws.com/stanford_videos/cs229/videos/01.1-Introduction-Welcome.mp4
http://s3.amazonaws.com/stanford_videos/cs229/videos/01.b-Introduction-WhatIsMachineLearning.mp4
http://s3.amazonaws.com/stanford_videos/cs229/videos/01.3-Introduction-SupervisedLearning.mp4
http://s3.amazonaws.com/stanford_videos/cs229/videos/01.d-Introduction-UnsupervisedLearning.mp4
http://s3.amazonaws.com/stanford_videos/cs229/videos/02.1-LinearRegressionWithOneVariable-ModelRepresentation.mp4
http://s3.amazonaws.com/stanford_videos/cs229/videos/02.2-LinearRegressionWithOneVariable-CostFunction.mp4
http://s3.amazonaws.com/stanford_videos/cs229/videos/02.3-LinearRegressionWithOneVariable-CostFunctionIntuitionI.mp4
http://s3.amazonaws.com/stanford_videos/cs229/videos/02.4-LinearRegressionWithOneVariable-CostFunctionIntuitionII.mp4
http://s3.amazonaws.com/stanford_videos/cs229/videos/02.5-LinearRegressionWithOneVariable-GradientDescent.mp4
http://s3.amazonaws.com/stanford_videos/cs229/videos/02.6-LinearRegressionWithOneVariabl
@forresty
forresty / rwget.sh
Created October 16, 2011 15:44
rwget: wget through ssh tunnel
#!/usr/bin/env sh
# TODO: replace your-hostname-here.com and path_to_your_rwget_folder
if [ $# -lt 1 ] ; then
echo "usage: rwget URL"
exit 1
fi
filename=`ssh your-hostname-here.com URL=$1 'bash -s' << 'ENDSSH'
cd path_to_your_rwget_folder
@forresty
forresty / down-all.rb
Created October 26, 2011 03:19
THIS IS EVIL...
#!/usr/bin/env ruby
require "uri"
require "open-uri"
require "nokogiri"
def extract_flv(page_url)
url = nil
open(page_url) { |page| page.read }.each_line do |line|
url = URI.unescape($1) if line =~ /to\.addVariable\(\"video_url\",\"(.*)\"\)/