Archive for October, 2010

24
Oct
10

StackOverflow bookmarklets


Sometimes I like to see only the questions that are interesting for me. For this I made the following bookmarklets:

  1. Show only interesting questions:

    
    var elements = document.getElementsByTagName("div");
    for(var i = 0;i < elements.length;i++) {
      	var one = elements[i];
    	if(one.className != "question-summary narrow tagged-interesting" && one.id.match("^question-summary"))   {
    		one.style.display = "none";
      	}
    };
    void(0);
    
  2. Hide uninteresting questions

    
    var elements = document.getElementsByTagName("div");
    for(var i = 0;i < elements.length;i++){
      var one = elements[i];
      if(one.className == "question-summary narrow tagged-ignored")   {
         one.style.display = "none";
      }
    };
    void(0);
    

To make them work, add a new bookmark to your browser, and in the address bar, add:javascript: and the code of one of the bookmarklets.
HTH.

Advertisements
20
Oct
10

finding duplicate files in a folder


Ruby script to find duplicate files in a folder. Example of md5 digest:


require "digest/md5"

abort "need folder" if ARGV.empty?
folder = ARGV.first.gsub(/\\/,"/")

files = Dir["#{folder}/**/*"].select {|f| File.file?(f)}
file_hashes = files.inject(Hash.new {|h,k| h[k] = []}) do |h,element|
	puts "analyzing #{element}"
	signature = Digest::MD5.hexdigest(File.read(element))
	h[signature] << element
	h
end

file_hashes.keys.select {|key| file_hashes[key].size > 1}.each {|k| puts file_hashes[k].inspect}

18
Oct
10

regex capture replace in notepad++


Example for replacement using captured group. Say this is the regex:
one(.*)two

and want to turn every word/phrase containing onesomethingtwo into threesomethingfour here’s how you use the group:

three\1four




Blog Stats

  • 226,733 hits