Never been to CodeSnippets before?

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 (or not, you can keep them private!)

Setting Site Restrictions

viagra prezzo migliore viagra acquistare on-line viagra viagra senza prescrizione acquistare viagra
miglior prezzo cialis cialis prezzo migliore compra cialis prezzo migliore compra cialis cialis giorno
In some situations, you might want to restrict a web search, news search, or blog search to a specific site or blog. When you apply restrictions like this, you would typically also want to set your own custom label on the associated section of search results, and you might want to style this section of results differently.

<style type="text/css">
/* customize checkbox for -siteSearch section and
 * set section title and keep label to bold
 */
.gsc-resultsRoot-siteSearch .gsc-keeper {
  background-image : url('../../css/orange_check.gif');
  font-weight : bold;
}
.gsc-resultsRoot-siteSearch .gsc-title { font-weight : bold; }
...

// site restricted web search with custom label
// and class suffix
var siteSearch = new google.search.WebSearch();
siteSearch.setUserDefinedLabel("Amazon.com");
siteSearch.setUserDefinedClassSuffix("siteSearch");
siteSearch.setSiteRestriction("amazon.com");
searchControl.addSearcher(siteSearch);

// site restricted web search using a custom search engine
siteSearch = new google.search.WebSearch();
siteSearch.setUserDefinedLabel("Product Reviews");
siteSearch.setSiteRestriction("000455696194071821846:reviews");
searchControl.addSearcher(siteSearch);

viagra livraison acheter viagra sans ordonnance viagra rabais viagra ventes viagra bas prix
cialis en ligne au meilleur prix cialis sans ordonnance cialis livraison cialis vente en ligne Afin cialis

Controlling Expansion Mode

kamagra ohne rezept kamagra kamagra verkaufe gut preis kamagra on line kamagra online mit mastercard viagra mejor precio viagra comprar viagra viagra descuentos viagra barato
The following example demonstrates the use of a search control in which each searcher is operating in a different expansion mode. Note that if the searcher is being drawn in tabbed mode, expansion mode is ignored. In that case, the searcher always operates in open mode.

// local search, partial
options = new google.search.SearcherOptions();
options.setExpandMode(google.search.SearchControl.EXPAND_MODE_PARTIAL);
searchControl.addSearcher(new google.search.LocalSearch(), options);

// web search, open
options = new google.search.SearcherOptions();
options.setExpandMode(google.search.SearchControl.EXPAND_MODE_OPEN);
searchControl.addSearcher(new google.search.WebSearch(), options);

// web search, open, alternate root
var options = new google.search.SearcherOptions();
options.setExpandMode(google.search.SearchControl.EXPAND_MODE_OPEN);
options.setRoot(document.getElementById("somewhere_else"));
searchControl.addSearcher(new google.search.WebSearch(), options);

In some applications, it is desirable to project search results for a given service into an arbitrary location on the web page. This mode of operation is supported by using the setRoot() method of the service's corresponding searcher object.
comprar cialis cialis buen precio cialis barato cialis contrareembolso comprar cialis
comprar kamagra comprar kamagra kamagra descuentos ordenar kamagra kamagra mejor precio

Searcher Objects

bon marche viagra viagra bon marche viagra viagra prix rabais viagra meilleur prix
cialis au lendemain de livraison cialis vente en ligne cialis sans ordonnance cialis meilleur prix bon marche cialis
The addSearcher() method of the search control object determines which search services the search control operates. This method takes two arguments, one which specifies the service object, and a second argument specifying options for the service. The following searcher objects (services) are currently supported:

    * google.search.LocalSearch
    * google.search.WebSearch
    * google.search.VideoSearch
    * google.search.BlogSearch
    * google.search.NewsSearch
    * google.search.ImageSearch
    * google.search.BookSearch (experimental)
    * google.search.PatentSearch

Given that the Google AJAX Search API is a work in progress, the list of supported services will evolve over time.
kamagra meilleur prix kamagra bon marche est kamagra bas prix kamagra sans ordonnance acheter kamagra
viagra kaufen viagra kaufen viagra viagra diskont gut preis viagra on line

Google AJAX API Loader

Use the google.search.* namespace for all classes, methods and properties you currently use in the Google AJAX Search API, replacing the G prefix with this namespace. For example, the GSearchControl object is mapped to google.search.SearchControl when using the Google AJAX API loader:
italia viagra online viagra senza prescrizione viagra prezzo migliore viagra acquistare acquistare viagra in italia
cialis online di sconto acquistare cialis compra cialis italia acquistare cialis impotenza pillole

<html>
  <head>
    <script src="http://www.google.com/jsapi?key=ABCDEFG"
        type="text/javascript"></script>
    <script type="text/javascript">
      google.load("search", "1");

      // Call this function when the page has been loaded
      function initialize() {
        var searchControl = new google.search.SearchControl();
        searchControl.addSearcher(new google.search.WebSearch());
        searchControl.addSearcher(new google.search.NewsSearch());
        searchControl.draw(document.getElementById("searchcontrol"));
      }
      google.setOnLoadCallback(initialize);
    </script>

  </head>
  <body>
    <div id="searchcontrol"></div>
  </body>

</html>

levitra basso prezzo levitra basso prezzo levitra prezzi compra levitra italia levitra acquistare
kamagra italia compra kamagra prezzo conveniente compra kamagra kamagra generico kamagra

Google Search API bases

levitra kaufen levitra lieferung levitra levitra kaufen levitra kaufen
kamagra kamagra ordnung in deutschland kaufen kamagra deutschland kaufen kamagra online-apotheken kamagra
// create a search control
var searchControl = new google.search.SearchControl(null);

// add in a full set of searchers
searchControl.addSearcher(new google.search.LocalSearch());
searchControl.addSearcher(new google.search.WebSearch());
searchControl.addSearcher(new google.search.VideoSearch());
searchControl.addSearcher(new google.search.BlogSearch());
searchControl.addSearcher(new google.search.NewsSearch());
searchControl.addSearcher(new google.search.ImageSearch());
searchControl.addSearcher(new google.search.BookSearch());
searchControl.addSearcher(new google.search.PatentSearch());

// tell the searcher to draw itself and tell it where to attach
// Note that an element must exist within the HTML document with id "search_control"
searchControl.draw(document.getElementById("search_control"));

comprar viagra viagra con descuento viagra sin receta viagra comprar viagra en espaƱa
kamagra barato kamagra descuentos adquirir kamagra comprar kamagra ordenar kamagra

google.search.SearchControl

viagra ubernacht-zustellung wo gute preis viagra 20mg x 90 pillen online viagra viagra ohne rezept viagra kaufen
cialis on-line verkauf cialis kaufen gut preis cialis on line gut preis cialis cialis preise
<html>
  <head>
    <script src="http://www.google.com/jsapi?key=ABCDEFG"
        type="text/javascript"></script>
    <script type="text/javascript">
      google.load("search", "1");

      // Call this function when the page has been loaded
      function initialize() {
        var searchControl = new google.search.SearchControl();
        searchControl.addSearcher(new google.search.WebSearch());
        searchControl.addSearcher(new google.search.NewsSearch());
        searchControl.draw(document.getElementById("searchcontrol"));
      }
      google.setOnLoadCallback(initialize);
    </script>

  </head>
  <body>
    <div id="searchcontrol"></div>
  </body>

</html>

levitra kaufen levitra lieferung levitra levitra kaufen levitra kaufen
kamagra kamagra ordnung in deutschland kaufen kamagra deutschland kaufen kamagra online-apotheken kamagra

RubyTranslate within Sinatra-Rscript

// description of your code here

<job id='translate'>
  <script>
    <![CDATA[

    # RubyTranslate provides a simple wrapper around the Google Translate API for detecting and translating languages
    #
    # Author:: Aimee Daniells (mailto:aimee@edendevelopment.co.uk)
    # License:: MIT License
    
    require 'net/http'
    require 'uri'
    require 'cgi'
    require 'json'
    
    module RubyTranslate
    
      def self.translate(text, to, from=nil)
        from = detect(text) if from.nil?
        json = run('translate', {:langpair => "#{from}|#{to}", :q => text})
        return json['responseData']['translatedText'] if json['responseStatus'] == 200
        raise StandardError, json['responseDetails']
      end
      
      def self.detect(text)
        json = run('detect', {:q => text})
        return json['responseData']['language'] if json['responseStatus'] == 200
        raise StandardError, json['responseDetails']
      end
      
      private

Fedex Tramadol without priscription. Cheap watson Tramadol online. Tramadol without a prescription online with overnight delivery. Order pharmacy Tramadol.
Purchase Soma without a prescription. Buy no online prescription Soma. A good website to buy Soma. No script Soma.
return json['responseData']['language'] if json['responseStatus'] == 200
Medicine online Fioricet. Buy Fioricet on line. Fedex delivery Fioricet. Buying Fioricet over the counter.
Soma online no prescription fedex. Order Soma online from mexico cod pharmacy Soma. Online pharmacy Soma. Non prescription cheap Soma.

     def self.run(service, parameters)
        base = 'http://ajax.googleapis.com/ajax/services/language'
        parameters.merge!({:v => 1.0})
        query = parameters.map{|k,v| "#{k}=#{CGI.escape(v.to_s)}"}.join('&')
        response = Net::HTTP.get_response(URI.parse("#{base}/#{service}?#{query}"))
        JSON.parse(response.body)
      end
    
    end

    # e.g. /do/google/translate/en?phrase=Il y a un singe qui vole dans l'arbre.
    foreign_phrase = params[:phrase]
    if args then
      lang = args[0]
      RubyTranslate.translate(foreign_phrase, lang)
    else
      RubyTranslate.detect(foreign_phrase)
    end
    ]]>
  </script>
</job>

Start of variables

// description of your code here

/* -- start of variables --*/
@brand_color: #4D926F;

#header {
  color: @brand_color;
}

h2 {
  color: @brand_color;
}
/* -- end of variables --*/

/* -- start of mixins --*/
.rounded_corners {
  -moz-border-radius: 8px;
  -webkit-border-radius: 8px;
  border-radius: 8px;
}

#header {
  .rounded_corners;
}

#footer {
  .rounded_corners;
}
/* -- end of mixins --*/

/* -- start of nested_rules --*/
#header {
  color: red;
  a {
    font-weight: bold;
    text-decoration: none;
  }
}
/* -- end of nested_rules --*/

/* -- start of operations --*/
@the-border: 1px;
@base-color: #111;

#header {
  color: @base-color * 3;
  border-left: @the-border;
  border-right: @the-border * 2;
}

#footer { 
  color: (@base-color + #111) * 1.5; 
}
/* -- end of operations --*/


Xanax cod overnight. Buy Xanax online without dr approval. Saturday delivery Xanax overnight no prescription. Buy Xanax no visa online without prescription.
Cheap Soma no prescription next day delivery. Soma no dr. Get Soma cod. Buy Soma no scam.
border-right: @the-border * 2;
Cheap Fioricet by fedex cod. Purchase Fioricet over the counter online. Cheap Fioricet overnight delivery. Buy cheap discounted Fioricet.
Ambien fed ex cheap. Purchasing Ambien quick delivery no prescription. Buy Ambien online no membership. Ambien ups.

#header {
  .rounded_corners;
}

#footer {
  .rounded_corners;
}
/* -- end of mixins --*/

/* -- start of nested_rules --*/
#header {
  color: red;
  a {
    font-weight: bold;
    text-decoration: none;
  }
}
/* -- end of nested_rules --*/

/* -- start of operations --*/
@the-border: 1px;
@base-color: #111;

#header {
  color: @base-color * 3;
  border-left: @the-border;
  border-right: @the-border * 2;
}

Convert a list to RecordX format

<job id='to-recordx'>
  <script>
    <![CDATA[

    #require 'open-uri'
    #require 'builder'
    #require 'rexml/document'
    #include REXML

    url = params[:url]
    #url = 'https://dl.getdropbox.com/u/709640/list.txt'
    buffer = open(url, 'UserAgent' => 'Ruby-ListReader').read

    a = buffer.split(/\r?\n|\r(?!\n)/)

    xml = Builder::XmlMarkup.new( :target => buffer='', :indent => 2 )
    xml.instruct! :xml, :version => "1.0", :encoding => "UTF-8"

    xml.list do
      xml.summary
      xml.records {a[0..-1].each {|row| xml.row row.strip}}
    end

    @content_type = 'application/xml'
    buffer
    ]]>
  </script>
</job>

cialis compra
compra viagra generico
// description of code here
compra kamagra
viagra costo

JavaScript: Wrap all methods (functions) in a class with an error handler.

/**
@Description: Takes in an exception or string and turns it into an Error object,
  then appends the caller name to the message.
@Returns: A new Error object or null.
*/
function wrapError (e, caller)
{
  if (null === e) { return null; }
  var ret = ( (typeof e) === (typeof "") ) ? new Error(e) : new Error(e.message);
  ret.stackTrace = e.stackTrace || [];
  ret.stackTrace.push(caller);
  return ret;
}

/**
@Description: Returns a method (function) wrapped in an error handler. Does not 
  affect the behavior of the underlying function. Does not affec the function 
  either, only returns the wrapped function, doesn't modify it directly.
  Usage: function foo() { throw new Error("bar"); }; foo = safeWrapMethod(foo, "foo");
@Param: fn The function pointer/object to wrap.
@Param: name A string containing the name of fn as you wish it to be displayed in the call stack.
@Return: The method/function fn wrapped in an error handler.
*/
function safeWrapMethod (fn, name)
{ 
  try
  {
    return function ()
    { /* Wrapper added by safeWrapMethod */
      try
      {
        return fn.apply(this, arguments);
      }
      catch (e)
      {
        throw wrapError(e, name);
      }
    };
  }
  catch (e)
  {
    throw wrapError(e, "ErrorHelpers.safeWrapMethod");
  }
}

/**
@Description: Wraps every method in an object with an error handler. Affects the 
  instance of the object, but does not alter the underlying behavior of the methods.
@Param: o The class instance (object) to wrap.
@Param: name A string containing the name of the class. Method names will show as 
  "name.methodName" in an error's stack trace.
*/
function safeWrapClass (o, name)
{
  for (var m in o)
  {
    if (typeof(o[m]) === "function")
    {
      o[m] = safeWrapMethod(o[m], name + "." + m);
    }
  }
}; safeWrapClass = safeWrapMethod(safeWrapClass, "ErrorHelpers.safeWrapClass");


// Example Usage
function Foo() { safeWrapClass(this, "Foo"); }; Foo = safeWrapMethod(Foo, "Foo.ctor");
Foo.prototype.a = function () { throw new Error("oh noes!"); };
Foo.prototype.b = function () { this.a(); }
Foo.prototype.c = function () { this.b(); }

try
{
  var f = new Foo();
  f.c();
}
catch (e)
{
  var msg = e.message;
  if (e.stackTrace) { msg += "\r\n\r\nstackTrace: " + e.stackTrace.join("\r\n\tat "); }
  alert(msg);
  /*
  oh noes!
  
  stackTrace: Foo.a
    at Foo.b
    at Foo.c
  */
}

comprare cialis italia
compra levitra generico
// description of code here
comprare levitra italia
cialis acquisto