google / urchin analytics
<body onload="_uacct='UA-XXXXXX-X';urchinTracker();init();">
11303 users tagging and storing useful source code snippets
Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
<body onload="_uacct='UA-XXXXXX-X';urchinTracker();init();">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"><head> <title>abc</title> <meta http-equiv="Content-Type" content="text/html; charset: UTF-8" /> </head> <body> <form action="http://www.google.com/search"> <div><input name="query" type="hidden" value="site:snippets.dzone.com"></input></div> <div><input maxlength="2048" name="q" size="55" title="Google Search" value="" ></input></div> <div><input name="btnG" type="submit" value="Google Search"></input></div> </form> </body> </html>
<FORM method=GET action=http://www.google.com/custom>; <A HREF=http://www.google.com/search>; <IMG SRC=http://www.google.com/logos/Logo_40wht.gif border=0 ALT=Google align=middle></A> <INPUT TYPE=text name=q size="10" maxlength=255 value=""> <INPUT type=submit name=sa VALUE="Just Goog It!"> <INPUT type=hidden name=cof VALUE="GIMP:darkblue;LW:380;ALC:red;L:http://blogs.salon.com/0001111/images/rfbanner.jpg;GFNT:lightblue;LC:red;LH:100;AH:left;VLC:gray;S:http://blogs.salon.com/0001111/;GALT:blue;AWFID:ba6ecf243ae3d16f;"><br /> >span class="small"> <input type=radio name=sitesearch value="blogs.salon.com" checked>Search blogs.salon.com <input type=radio name=sitesearch value="">Search the Web</span><br /> </FORM>
(function($) { /* function searchAddress(jmap, address, settings) * This function is an internal plugin method that returns a GLatLng that can be passed * to a Google map. */ function searchAddress(jmap, address, settings) { if (jmap._mapType) { alert('Yahoo Maps Geocoding not yet supported'); } if (jmap.i.Au) { GGeocoder = new GClientGeocoder(); GGeocoder.getLatLng(address, function(point){ if (!point) { alert(address + " not found"); } else { jmap.setCenter(point,settings.zoom); var marker = new GMarker(point, {draggable: true}); jmap.addOverlay(marker); pointlocation = marker.getPoint(); marker.openInfoWindowHtml("Latitude: " + pointlocation.lat() + "<br />Longitude: " + pointlocation.lng()); GEvent.addListener(marker, "dragend", function(){ mylocation = marker.getPoint(); marker.openInfoWindowHtml("Latitude: " + pointlocation.lat() + "<br />Longitude: " + pointlocation.lng()); }); } }); } } /* directions: function(map,query, panel) * Takes a Direction query and returns directions for map. Optional panel for text information */ function searchDirections(jmap,query,panel) { // Yahoo Maps if (jmap._mapType) { alert('Yahoo Directions support not yet added') ; } // Google Maps if (jmap.i.Au) { var dirpanel = document.getElementById(panel); directions = new GDirections(jmap, dirpanel); directions.load(query); } } $.fn.extend({ /* jmap: function(settings) * The constructor method * Example: $().jmap(); */ jmap: function(settings) { var version = "1.3"; /* Default Settings*/ var settings = jQuery.extend({ provider: "google", // can be "google" or "yahoo" maptype: "hybrid", // can be "map", "sat" or "hybrid" center: [55.958858,-3.162302], // G + Y zoom: 12, // G + Y controlsize: "small", // G + Y showtype: true, // G + Y showzoom: true, // Y showpan: true, // Y showoverview: true, // G showscale: true, // Y dragging: true, // G + Y scrollzoom: true, // G + Y smoothzoom: true, // G searchfield: "#Address", searchbutton: "#findaddress", directionsto: "#to", directionsfrom: "#from", directionsfind: "#getDirections", directionspanel: "myDirections" },settings); return this.each(function(){ switch(settings.provider) { case "yahoo": var jmap = this.jMap = new YMap(this); switch(settings.maptype) { case "map": var loadmap = YAHOO_MAP_REG; break; case "sat": var loadmap = YAHOO_MAP_SAT; break; default: var loadmap = YAHOO_MAP_HYB; break; } jmap.setMapType(loadmap); jmap.drawZoomAndCenter(new YGeoPoint(settings.center[0],settings.center[1]), settings.zoom); if (settings.showtype == true){ jmap.addTypeControl(); // Type of map Control } if (settings.showzoom == true && settings.controlsize == "small" ){ jmap.addZoomShort(); // Small zoom control } if (settings.showzoom == true && settings.controlsize == "large" ){ jmap.addZoomLong(); // Large zoom control } if (settings.showpan == true) { jmap.addPanControl(); // Pan control } if (settings.showscale == false) { /* On by default */ jmap.removeZoomScale(); // Show scale bars } if (settings.dragging == false) { /* On by default */ jmap.disableDragMap(); // Is map draggable? } if (settings.scrollzoom == false) { /* On by default */ jmap.disableKeyControls(); // Mousewheel and Keyboard control } break; case "mslive": alert('Microsoft Live Maps are currently not supported but planned for version 1.4') break; default: var jmap = this.jMap = new GMap2(this); switch(settings.maptype) { case "map": var loadmap = G_NORMAL_MAP; break; case "sat": var loadmap = G_SATELLITE_MAP; break; default: var loadmap = G_HYBRID_MAP; break; } jmap.setCenter(new GLatLng(settings.center[0],settings.center[1]),settings.zoom,loadmap); switch(settings.controlsize) { case "small": jmap.addControl(new GSmallMapControl()); break; case "large": jmap.addControl(new GLargeMapControl()); break; case "none": break; default: jmap.addControl(new GSmallMapControl()); } if (settings.showtype == true){ jmap.addControl(new GMapTypeControl()); } if (settings.showoverview == true){ jmap.addControl(new GOverviewMapControl()); } if (settings.scrollzoom == true) { /* Off by default */ jmap.enableScrollWheelZoom(); } if (settings.smoothzoom == true) { /* Off by default*/ jmap.enableContinuousZoom(); } if (settings.dragging == false) { /* On by default */ jmap.disableDragging(); } } /* Seach for the lat & lng of our address*/ jQuery(settings.searchbutton).bind('click', function(){ searchAddress(jmap, jQuery(settings.searchfield).attr('value'), settings); }); /* Search for Directions */ jQuery(settings.directionsfind).bind("click", function(){ var from = $(settings.directionsfrom).attr('value'); var to = $(settings.directionsto).attr('value'); searchDirections(jmap, "from: " + from + " to: " + to, settings.directionspanel); $(settings.directionsfrom).attr('value', to); $(settings.directionsto).attr('value', ''); return false; }); /* On document unload, clean unload Google API*/ jQuery(document).unload(function(){ GUnload(); }); }); }, /* myMap: function() * Returns a map object from the API, so it's available to the user * Example: $().myMap().setCenter(...) for Google; * Example: $().myMap().drawZoomAndCenter(...) for Yahoo; */ myMap: function() { return this[0].jMap; }, /* addPoint: function() * Returns a marker to be overlayed on the Google map * Example: $().addPoint(...); */ addPoint: function(pointlat, pointlng, pointhtml, isdraggable, removable) { var jmap = this[0].jMap; // Yahoo Maps if (jmap._mapType) { var marker = new YMarker(new YGeoPoint(pointlat, pointlng)); // Create the Yahoo marker type YEvent.Capture(marker, EventsList.MouseClick, function(){ // Add mouseclick to open HTML marker.openSmartWindow(pointhtml); }); // Below code does not work as expected /*if (removable == true) { YEvent.Capture(marker, EventsList.MouseDoubleClick, function(){ jmap.removeOverlay(marker); }); }*/ jmap.addOverlay(marker); // Add marker to map } // Google Maps if (jmap.i.Au) { var marker = new GMarker(new GLatLng(pointlat,pointlng), { draggable: isdraggable } ); GEvent.addListener(marker, "click", function(){ marker.openInfoWindowHtml(pointhtml); }); if (removable == true) { GEvent.addListener(marker, "dblclick", function(){ return jmap.removeOverlay(marker); }); } return jmap.addOverlay(marker); } }, /* addPoly: function(poly) * Takes an array of GLatLng points, converts it to a vector Polyline to display on the map * Example: $().addPoly(...); */ addPoly: function (poly, colour, width, alpha) { var jmap = this[0].jMap; // Yahoo Maps if (jmap._mapType) { return jmap.addOverlay(poly, colour, width, alpha); } // Google Maps if (jmap.i.Au) { return jmap.addOverlay(poly); } }, /* addRss: function() * Takes a KML file and renders it to the map. * Example: $().addPoint(...); */ addRss: function (rssfile) { var jmap = this[0].jMap; // Yahoo Maps if (jmap._mapType) { var geoXml = new YGeoRSS(rssfile); return jmap.addOverlay(geoXml); } // Google Maps if (jmap.i.Au) { var geoXml = new GGeoXml(rssfile); return jmap.addOverlay(geoXml); } } }); })(jQuery);
tr <FROM>|<TO>
tr en|de tr en|fr tr en|pt tr de|en
javascript:location.href='http://translate.google.com/translate?u='+encodeURIComponent(location.href)+'&langpair=%s&hl=EN&ie=UTF-8&oe=UTF-8&prev=%2Flanguage_tools'
require 'rubygems' require 'cgi' require 'open-uri' require 'hpricot' q = %w{meine kleine suchanfrage}.map { |w| CGI.escape(w) }.join("+") url = "http://www.google.com/search?q=#{q}" doc = Hpricot(open(url).read) lucky_url = (doc/"div[@class='g'] a").first["href"] system 'open #{lucky_url}'
import sys,xmpp # Google Talk constants FROM_GMAIL_ID = "user@gmail.com" GMAIL_PASS = "password" GTALK_SERVER = "talk.google.com" TO_GMAIL_ID = "user@gmail.com" jid=xmpp.protocol.JID(FROM_GMAIL_ID) cl=xmpp.Client(jid.getDomain(),debug=[]) if not cl.connect((GTALK_SERVER,5222)): raise IOError('Can not connect to server.') if not cl.auth(jid.getNode(),GMAIL_PASS): raise IOError('Can not auth with server.') cl.send( xmpp.Message( "someone@gmail.com" ,"Hi" ) ) cl.disconnect()
require "open-uri" require "cgi" # Command line arguments ... $*.each {|argu| argu.gsub!("\"","")} # Defaults towns src = "Lyon" dest = "Paris" # If we have fill two aguments ... if $*.size == 2 then src = $*[0] dest = $*[1] end html = "" url = "http://maps.google.com/maps?f=d&hl=fr&saddr=" + CGI.escape(src) + "&daddr="+ CGI.escape(dest) # Read the html page open(url) {|f| f.each_line {|line| html += line} } pos1 = html.index("voiture") # French version pos2 = html.index("</td>",pos1) unless pos1 == nil pos1 = html.index(">",pos2+6)+1 unless pos2 == nil pos2 = html.index("</td>",pos2+1) -1 unless pos2 == nil ret = "" if pos1 != nil and pos2 != nil ret = html[pos1..pos2].gsub!(" ", " ") else ret = "0" end html = nil p ret
#!/usr/bin/env ruby -w if ARGV.empty? puts <<-T Locate IP by haqu usage: ./lip.rb ip|domain ... T exit end require 'net/http' require 'uri' uri = URI.parse('http://www.maxmind.com/app/locate_ip') res = Net::HTTP.post_form(uri, { 'ips' => ARGV.join(' '), 'type' => '', 'u' => '', 'p' => '' } ) fstr = res.body fstr.gsub!("Edition Results<\/span><p>","CHECKPOINT") fstr =~ /CHECKPOINT(.+?)<\/table>/m fields = $1.grep(/<(th|td)>/) fields.each do |f| f.strip! f.gsub!(/<[^>]+>/,"") end (0...13).each do |i| puts ". #{fields[i]}: #{fields[i+13]}" end maplink = "http://maps.google.com/maps?q=#{fields[20]},+#{fields[21]}&iwloc=A&hl=en" puts ". Google Maps URL: #{maplink}"
#!/usr/bin/env ruby # -*- coding: utf-8 -*- # $Id: google-pr.rb,v b205c14e4ef5 2007-01-15 13:53 +0300 $ # (C) 2006-2007 under terms of LGPL v2.1 # by Vsevolod S. Balashov <vsevolod@balashov.name> # based on 3rd party code snippets (see comments) require 'uri' require 'open-uri' module SEO # http://blog.outer-court.com/archive/2004_06_27_index.html#108834386239051706 class GooglePR def initialize(uri) @uri = uri end M=0x100000000 # modulo for unsigned int 32bit(4byte) def m1(a,b,c,d) (((a+(M-b)+(M-c))%M)^(d%M))%M # mix/power mod end def i2c(i) [i&0xff, i>>8&0xff, i>>16&0xff, i>>24&0xff] end def c2i(s,k=0) ((s[k+3].to_i*0x100+s[k+2].to_i)*0x100+s[k+1].to_i)*0x100+s[k].to_i end def mix(a,b,c) a = a%M; b = b%M; c = c%M a = m1(a,b,c, c >> 13); b = m1(b,c,a, a << 8); c = m1(c,a,b, b >> 13) a = m1(a,b,c, c >> 12); b = m1(b,c,a, a << 16); c = m1(c,a,b, b >> 5) a = m1(a,b,c, c >> 3); b = m1(b,c,a, a << 10); c = m1(c,a,b, b >> 15) [a, b, c] end def old_cn(iurl = 'info:' + @uri) a = 0x9E3779B9; b = 0x9E3779B9; c = 0xE6359A60 len = iurl.size k = 0 while (len >= k + 12) do a += c2i(iurl,k); b += c2i(iurl,k+4); c += c2i(iurl,k+8) a, b, c = mix(a, b, c) k = k + 12 end a += c2i(iurl,k); b += c2i(iurl,k+4); c += (c2i(iurl,k+8) << 8) + len a,b,c = mix(a,b,c) return c end def cn ch = old_cn ch = ((ch/7) << 2) | ((ch-(ch/13).floor*13)&7) new_url = [] 20.times { i2c(ch).each { |i| new_url << i }; ch -= 9 } ('6' + old_cn(new_url).to_s).to_i end def request_uri # http://www.bigbold.com/snippets/posts/show/1260 + _ -> %5F "http://toolbarqueries.google.com/search?client=navclient-auto&hl=en&ch=#{cn}&ie=UTF-8&oe=UTF-8&features=Rank&q=info:#{URI.escape(@uri, /[^-.!~*'()a-zA-Z\d]/)}" end def page_rank(uri = @uri) @uri = uri if uri != @uri open(request_uri) { |f| return $1.to_i if f.string =~ /Rank_1:\d:(\d+)/ } nil end private :m1, :i2c, :c2i, :mix, :old_cn attr_accessor :uri end end if __FILE__ == $0 and 1 == ARGV.size puts SEO::GooglePR.new(ARGV[0]).page_rank end