├── .gitignore ├── bookmarklets ├── .DS_Store ├── fill_form_fields │ ├── .DS_Store │ ├── Rakefile │ ├── README │ ├── fill_form_fields.js │ ├── fill_form_fields_src.js │ └── index.html └── show_tag_counts │ └── show_tag_counts.js ├── video_encoding_for_iphone ├── mencoder ├── README └── encode.rb └── rails_log_analysis └── analyz.rb /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | **/.DS_Store 3 | -------------------------------------------------------------------------------- /bookmarklets/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bloopletech/scripts/HEAD/bookmarklets/.DS_Store -------------------------------------------------------------------------------- /video_encoding_for_iphone/mencoder: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bloopletech/scripts/HEAD/video_encoding_for_iphone/mencoder -------------------------------------------------------------------------------- /bookmarklets/fill_form_fields/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bloopletech/scripts/HEAD/bookmarklets/fill_form_fields/.DS_Store -------------------------------------------------------------------------------- /bookmarklets/fill_form_fields/Rakefile: -------------------------------------------------------------------------------- 1 | desc "Build final fill_form_fields.js" 2 | task :build do 3 | src = File.read(File.dirname(__FILE__) + "/fill_form_fields_src.js") 4 | File.open(File.dirname(__FILE__) + "/fill_form_fields.js", "w") { |f| f << "javascript:#{src.gsub("\n", " ").gsub(/ +/, ' ').strip}" } 5 | end 6 | 7 | task :default => :build 8 | -------------------------------------------------------------------------------- /bookmarklets/show_tag_counts/show_tag_counts.js: -------------------------------------------------------------------------------- 1 | javascript:var n=document.getElementsByTagName('*');var o=[];for(var i=0;i0) {o[x].c++;}else{o.push({m:n[i].nodeName,c:1});}}o=o.sort(function(a,b){return(a.cb.c?-1:0);});for(var i=0;i 0) { for(var i = 0; i < w.frames.length; i++) { fill_window(w.frames[i]); } } }; fill_window(window.top); })(); void(0); -------------------------------------------------------------------------------- /video_encoding_for_iphone/README: -------------------------------------------------------------------------------- 1 | Convert video for the iPhone/iPod Touch 2 | ======================================= 3 | 4 | This script will convert video for play on the iPhone/iPod Touch. To use the script, run: 5 | 6 | ruby encode.rb 7 | 8 | This will resize, reencode, and if the source movie has soft subtitles, convert them to hard subtitles. 9 | 10 | Then, connect the iPhone/iPod Touch, go to iTunes, make sure sync is turned on in the settings for the device, and drag the converted movie (it will be in the current directory with an m4v extension) onto the 'Movies' list for the device (located in the sidbar in iTunes). Sync the device. The movie will show up on the device. 11 | 12 | This script requires mplayer/mencoder to be installed; if you need assistance in installing mplayer, try the #mplayer IRC channel on freenode. 13 | 14 | If you encounter problems using the script, open up encode.rb; it has many useful comments. Also try running encode.rb with the --no-encode argument, and the script will print the raw command passed to mencoder; you can give this line to the people in the #mplayer IRC channel, and they may be able to help you. 15 | -------------------------------------------------------------------------------- /bookmarklets/fill_form_fields/fill_form_fields_src.js: -------------------------------------------------------------------------------- 1 | (function() 2 | { 3 | function handle_inputs(inputs) 4 | { 5 | for(var i = 0; i < inputs.length; i++) 6 | { 7 | if(inputs[i].tagName.toLowerCase() == 'select') 8 | { 9 | inputs[i].selectedIndex = inputs[i].options.length - 1; 10 | } 11 | else if(/^radio|checkbox$/.test(inputs[i].type)) 12 | { 13 | inputs[i].checked = true; 14 | } 15 | else if(/^text|password$/.test(inputs[i].type) || inputs[i].tagName.toLowerCase() == 'textarea') 16 | { 17 | if(/email/i.test(inputs[i].name)) 18 | { 19 | inputs[i].value = "t" + Math.round(Math.random()*10000) + "@mailinator.com"; 20 | } 21 | else if(/date/i.test(inputs[i].name)) 22 | { 23 | inputs[i].value = (new Date()).toDateString(); 24 | } 25 | else 26 | { 27 | inputs[i].value = "test"; 28 | } 29 | } 30 | } 31 | }; 32 | 33 | function fill_window(w) 34 | { 35 | var w_document = (w.window || w.contentWindow).document; 36 | 37 | handle_inputs(w_document.getElementsByTagName('input')); 38 | handle_inputs(w_document.getElementsByTagName('textarea')); 39 | handle_inputs(w_document.getElementsByTagName('select')); 40 | 41 | if(w_document.designMode == 'on' || w_document.body.contentEditable == 'true') 42 | { 43 | w_document.body.innerHTML = 'test'; 44 | } 45 | 46 | if(w.frames.length > 0) 47 | { 48 | for(var i = 0; i < w.frames.length; i++) 49 | { 50 | fill_window(w.frames[i]); 51 | } 52 | } 53 | }; 54 | 55 | fill_window(window.top); 56 | })(); 57 | void(0); 58 | -------------------------------------------------------------------------------- /bookmarklets/fill_form_fields/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Fill Form Fields Test Page 5 | 6 | 7 | 8 |
9 | The following are standard form fields. 10 |
11 | 12 |
13 | 14 |
15 | 16 |
17 | 18 |
19 | 24 |
25 | One 26 |
27 | Two 28 |
29 | Three 30 |
31 | One 32 |
33 | Two 34 |
35 | Three 36 |
37 | 39 |
40 | 41 |
42 | Add source script 43 | Add built script 44 | 45 | 46 | -------------------------------------------------------------------------------- /rails_log_analysis/analyz.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/ruby 2 | 3 | require 'date' 4 | 5 | class String 6 | def blank? 7 | self.length == 0 8 | end 9 | end 10 | 11 | ERROR_REGEXES = [/\(500 Internal Server Error\)$/m, /\(500 Internal Error|\)$/m, /\(404 Page Not Found\)$/m] 12 | 13 | 14 | print "Requests from which IP? [ip or nothing] " 15 | ip = $stdin.gets.chomp 16 | print "Consider requests going back to [date or nothing] " 17 | date_str = $stdin.gets.chomp 18 | date = date_str.length == 0 ? nil : Date.parse(date_str) 19 | print "Show errors only? [y/n] " 20 | show_errors_only = $stdin.gets.chomp == 'y' 21 | print "Type of error to look for [class or nothing] " 22 | error_type = $stdin.gets.chomp 23 | print "Type of error to ignore [class or nothing] " 24 | ignore_error_type = $stdin.gets.chomp 25 | print "Request to look for [class#[optional action] or nothing] " 26 | request = $stdin.gets.chomp 27 | 28 | file = File.open(ARGV[0], 'r') 29 | 30 | while (line = file.gets) do 31 | if line.index("Processing ") == 0 32 | line =~ /^Processing (.*?) \(for (.*?) at (.*?) (\d+):(\d+):(\d+)\)/ 33 | if !date.nil? and Date.parse($3) < date 34 | next 35 | end 36 | if ip.length > 0 and $2 != ip 37 | next 38 | end 39 | if request.length > 0 and $1 =~ /^#{Regexp.quote(request)}/ 40 | next 41 | end 42 | 43 | body = line 44 | 45 | body_line = nil 46 | body << body_line while (body_line = file.gets) && !body_line.index("Processing") 47 | line = body_line 48 | 49 | 50 | body.rstrip! 51 | 52 | next if show_errors_only && !ERROR_REGEXES.detect { |r| body =~ r } 53 | 54 | if (error_type.blank? && ignore_error_type.blank?) || (!error_type.blank? && body.include?(error_type)) || 55 | (!ignore_error_type.blank? && !body.include?(ignore_error_type)) 56 | puts body 57 | puts "\n==============================================================================================================================================\n\n" 58 | end 59 | 60 | body_line ? redo : break 61 | end 62 | end 63 | -------------------------------------------------------------------------------- /video_encoding_for_iphone/encode.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/ruby 2 | =begin 3 | Depends on recent mplayer with libfaac and libx264 installed before compiling/installing mplayer. 4 | Also, to read AAC audio, libfaad, and to read MP3 audio, libmp3lame, must be installed before compiling/installing mplayer. 5 | If these requirements are not met, don't even try to run this script. 6 | 7 | Mencoder may warn about "REMEMBER: MEncoder's libavformat muxing is presently broken"; this is irrelevant for encoding videos in H.264 for the iPod Touch/iPhone, 8 | as they don't use B-frames. 9 | 10 | Usage: 11 | encode.rb 12 | 13 | Options are: 14 | --no-encode Prints the encoding command, but doesn't run it 15 | --ipod Encodes for the ipod nano 5g instead of ipod touch. 16 | # --more-keyframes Adds a keyframe every 3 seconds, instead of every 10 (approx.) seconds. Makes seeking better, but also makes file size larger. 17 | =end 18 | 19 | class Float 20 | def round_nearest_even_integer 21 | (self / 2.0 + 0.5).to_i * 2 22 | end 23 | end 24 | 25 | allowed_opts = %w(--no-encode --more-keyframes --ipod) 26 | 27 | opts = ARGV & allowed_opts 28 | 29 | (ARGV - allowed_opts).each do |movie| 30 | if ARGV.include?("--ipod") 31 | max_output_width = 376 32 | max_output_height = 240 33 | else 34 | max_output_width = 480 35 | max_output_hieght = 320 36 | end 37 | 38 | movie_path = File.expand_path(movie) 39 | escaped_movie_path = movie_path.gsub(/([ \[\]\(\)'"])/) { |r| "\\#{$1}" } #shell escape the input filename 40 | 41 | #set the output filename to only contain safe characters, and tp have the m4v extension 42 | output_filename = "#{File.basename(movie).gsub(/\..*{3}/, '').gsub(/[^A-z0-9_-]/, '_')}.m4v" 43 | 44 | =begin 45 | get some information about the input movie; the options are: 46 | * -identify tells mplayer to print the info on the movie that we need 47 | * -frames 0 tells mplayer to quit as soon as we have the info 48 | * -nomsgcolor stops mplayer form outputting special characters that print nice colours in the shell; without this, 49 | it'd be more of a pain to read the data we want. 50 | =end 51 | movie_info = IO.popen("mplayer -identify -frames 0 -nomsgcolor #{escaped_movie_path} &2>1") { |s| s.read } 52 | lines = movie_info.split("\n") 53 | 54 | =begin 55 | get the reported width, height, and aspect ratio of the input movie. If the aspect is not 0, 56 | then we get the width of the movie by multiplying the height by the aspect ratio; this avoids problems when the movie needs 57 | to be scaled horizontally before being displayed. If he aspect ratio is 0, then the reports height is used as the height of the input. 58 | =end 59 | height = lines.detect { |l| l =~ /^ID_VIDEO_HEIGHT=/ }.split("=").last.to_i 60 | reported_width = lines.detect { |l| l =~ /^ID_VIDEO_WIDTH=/ }.split("=").last.to_i 61 | aspect = lines.detect { |l| l =~ /^ID_VIDEO_ASPECT=/ }.split("=").last.to_f 62 | #puts "reported_height: #{height}, reported_width: #{reported_width}, aspect: #{aspect}" 63 | 64 | width = aspect > 0 ? height * aspect : reported_width 65 | 66 | #Resize 67 | true_ratio = height / max_output_height.to_f 68 | new_height = (height / true_ratio).round_nearest_even_integer 69 | new_width = (width / true_ratio).round_nearest_even_integer 70 | 71 | if new_height > max_output_height || new_width > max_output_width 72 | true_ratio = width / max_output_width.to_f 73 | new_height = (height / true_ratio).round_nearest_even_integer 74 | new_width = (width / true_ratio).round_nearest_even_integer 75 | end 76 | #End resize 77 | 78 | width = new_width 79 | height = new_height 80 | 81 | height_expand = -(240 - height) 82 | width_expand = -(376 - width) 83 | 84 | subs = !!lines.detect { |l| l =~ /^ID_SUBTITLE_ID=/ } 85 | 86 | =begin 87 | The code that follows is the really important part. The code above is just to get the right widths and heights to scale to, and to work out 88 | whether to convert hardsubs => softsubs or not. 89 | 90 | video_filter_cmd scales the video input to a fixed output size of 480x320 (the native resolution of the iPod Touch / iPhone). 91 | Specifically, the options work as follows: 92 | * the scale option sets the output size to be 480x(scaled height if input video); 93 | * the expand option adds black bars to the video to make it 320 pixels high; 94 | * the harddup option ensures that, when the input video has soft-duplicated frames, the output video has the frame actually duplicated 95 | (this is needed otherwise the audio loses syncronization with the video); 96 | * the noskip option make sure the no video frames are skipped (without this, audio loses sync with the video); 97 | * and the mc 0 otion sets the amount of drift between the audio and the video to nothing, to ensure the audio syncs with the video. 98 | 99 | output_format_cmd does the work needed to make sure the video/audio output will actually play on the iPod Touch/iPhone. THe options are as follows: 100 | * -oac faac tells mencoder to encode AAC audio on the output; 101 | * I don't actually know mpeg=4, object=2, and raw do, but those options have been reccomended, and it works with them so I've left it; 102 | I suspect they are a part of ensuring the audio is 'LC' or Low Complexity; 103 | * The br=128 option sets the audio bitrate to 128kb/s, which AFAIK makes sure the audio is LC; 104 | * -ovc x264 tells mencoder to encode the video as H.264; 105 | * bframes=0,nocabac,global_header,no8x8dct,weightp=0 are the options needed to make the video output H.264 Baseline, as opposed to H.264 Main etc. 106 | Without these options, the video will not play on an iPod Touch/iPhone. 107 | 108 | subs_cmd controls the way the subtitles are converted from softsubs to hardsubs, if the input movie has softsubs. The options are as follows: 109 | * -subfont-autoscale 0 tells mencoder to not scale the subtitle font size automatically; 110 | * -subfont-text-scale 20 sets the font size of the subtitles to be %20 the height of the movie. 111 | * -subpos 99 puts the bottom edge of the subtitles at 99% from the top of the movie; 112 | * -subfont-blur 2 puts a 2 pixel gaussian blur around the subtitle text; 113 | * -subfont-outline 1 puts a 1 pixel outline around the subtitle text. 114 | 115 | The mencoder command itself has a -of lavf option; this tells mencoder to use the lavf encoder (part of ffmpeg) to encode the movie; this allows us 116 | to set the options above. 117 | 118 | If the movie won't even copy or play at all on the device, outut_format_cmd is the first thing to change. 119 | =end 120 | 121 | video_filter_cmd = "-vf scale=#{width}:#{height},expand=#{width_expand}:#{height_expand}:#{subs ? '0:0' : ':'}:1,harddup -noskip -mc 0" 122 | output_format_cmd = "-oac faac -faacopts mpeg=4:object=2:raw:br=128 -ovc x264 -x264encopts bframes=0:nocabac:global_header:no8x8dct:weightp=0" 123 | subs_cmd = subs ? '-subfont-autoscale 0 -subfont-text-scale 20 -subpos 99 -subfont-blur 2 -subfont-outline 1' : '' 124 | 125 | cmd = "mencoder -o #{output_filename} -of lavf #{video_filter_cmd} #{output_format_cmd} #{subs_cmd} '#{movie}' &2>1" 126 | puts cmd 127 | system cmd unless opts.include?('--no-encode') 128 | 129 | =begin 130 | If mencoder crashes with a segfault, then try this instead of the above section. This script has worked for me in cases where the above has not. 131 | Note that you need to install ffmpeg additionally, and separately, from mencoder. FFMpeg needs libfaac, libfaad, and libx264 compiled in. 132 | =end 133 | =begin 134 | File.delete("/tmp/movie.avi") if File.exists?("/tmp/movie.avi") 135 | 136 | cmd = "mencoder -o /tmp/movie.m4v -of lavf #{video_filter_cmd} #{output_format_cmd} '#{movie}' &2>1" 137 | puts cmd 138 | system cmd unless opts.include?('--no-encode') 139 | 140 | cmd = "ffmpeg -i /tmp/movie.avi -acodec copy -vcodec copy #{output_filename}" 141 | puts cmd 142 | system cmd unless opts.include?('--no-encode') 143 | 144 | File.delete("/tmp/movie.avi") if File.exists?("/tmp/movie.avi") 145 | =end 146 | end --------------------------------------------------------------------------------