/** @id sipleSwitcher
* @classDescription Very simple style switcher using jQuery
*/
$(document).ready(function(){
$('#styleSwitch .button').bind('click', function(){
$('body').removeClass();//remove all the other classes
$('#styleSwitch .button').removeClass('selected');
$(this).addClass('selected');
switch(this.id){
case 'style1':
$('body').addClass('style1');
break;
case 'style2':
$('body').addClass('style2');
break;
case 'style3':
$('body').addClass('style3');
break;
}
return false;
});
});
Tag Archive for example
jQuery Simple Style Switcher
Function Template
/* Function: <Function, ex. my_function( $param1, $param2 )> Description: <Description of what it does> Parameters: <Parameters for function> Example: <Show an example of your function in use, ex. my_function( "thisparameter", "newparameter");> Requirements: <Anything that your function requires> Notes: <Any other comments you have> Author: <your name and email/website address> */
Category: Uncategorized |
Tags: author, description, example, function, notes, parameters, requirements, template
append_content
function append_content($text) {
if ( $this->initem ) {
$this->concat( $this->current_item[ $this->incontent ], $text );
}
elseif ( $this->inchannel ) {
$this->concat( $this->channel[ $this->incontent ], $text );
}
}
Reusable Box with Images and CSS (implements a non-semantic variant of Sliding Doors)
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<!--** Time-stamp: <[box.html] modified by Noah Sussman on Saturday, 2007.04.07 at 12 : 41 : 08 on GRIMOIRE> **-->
<title>Reusable Box (sliding doors)</title>
<style type="text/css">
/****************************************************************
** Reusable Box
** This is an image-based box design, which allows arbitrary
** expansion up to the width and height of its component images.
** See the "Sliding Doors of CSS" series of articles at A List Apart
** for in-depth explanation.
** Note that I have not actually implemented "Slding Doors," as the
** markup here is anything but semantic.
****************************************************************/
body { background: url(images/mars.png) }
.reusableBox {
background: url(images/left.png) no-repeat;
margin-left: -10px; /* Using a negative margin to avoid overlap of transparent images. I learned to do this by reading css-discuss. NS 2007.04.06 */
position: absolute;
}
.reusableBox .presentationTop {
background: url(images/top.png) no-repeat top right;
margin-left: 10px;
/* padding-top: 10px; */
}
.reusableBox .rbContent {
padding-top: 20px;
padding-left: 10px; /* another 10px is added by the margin of presentationTop */
padding-right: 20px;
position: relative;
}
.reusableBox .presentationBottom {
height: 10px;
background: url(images/bottom.png) no-repeat bottom right;
position: relative;
top: 10px;
}
.reusableBox .presentationLeftBottom {
height: 10px;
width: 10px;
margin-left: -10px;
margin-bottom: -10px;
background: url(images/bottom.png) no-repeat top left;
position: relative;
}
.reusableBox .rbNipple {
background: url(images/nipple.png) no-repeat;
width: 15px;
height: 11px;
position: absolute;
top: 4px;
left: 22px;
}
.rbSource { display: none; } /* this line is optional */
/* styles below here apply to the example implementations */
div#foo {
width: 320px; /* set the width of each box by its id */
top: 40px;
left: 500px;
position: relative;
}
div#downBalloon {
width: 200px;
top: 110px;
left: 740px;
position: relative;
}
div#downBalloon .rbNipple {
left: 134px;
}
p { display: inline; } /* optional */
code { display: block; padding: .3em; } /* optional */
</style>
<script type="text/javascript">
function makeWeb2Box(elId, width, top, left, hasNipple, nippleOffset) {
var el = document.getElementById(elId);
var elContainer = document.createElement('div');
elContainer.className="reusableBox";
elContainer.style.width = width;
elContainer.style.top = top;
elContainer.style.left = left;
var offset = (nippleOffset ? 'style="left: '+ nippleOffset +'px"' : '');
var nipple = (hasNipple ? '<div class="rbNipple"' + offset + '></div>' : '');
elContainer.innerHTML = '<div class="presentationTop"><div class="rbContent">' +
el.innerHTML +
'</div><div class="presentationBottom"><div class="presentationLeftBottom">' +
nipple +
'</div></div></div>';
el.parentNode.insertBefore(elContainer, el);
el.parentNode.removeChild(el);
}
window.onload = function() {
makeWeb2Box('bar', 400, 10, 40, true, 102);
makeWeb2Box('jsBox', 200, 300, 400);
}
</script>
</head>
<body>
<!-- snippet #1 -->
<div class="reusableBox" id="foo">
<div class="presentationTop">
<div class="rbContent">
<!-- snippet #1 ends -->
<p>Reusable box built with css </p>
<!-- snippet #2 -->
</div><!-- end of rbContent -->
<div class="presentationBottom">
<div class="presentationLeftBottom">
</div><!-- end of presentationLeftBottom -->
</div><!-- end of presentationBottom -->
</div><!-- end of presentationTop -->
</div><!-- end of reusableBox -->
<!-- snippet #2 ends -->
<div class="reusableBox" id="downBalloon">
<div class="presentationTop">
<div class="rbContent">
<h3>mars</h3>
<p>this is a popup built with css</p>
</div><!-- end of rbContent -->
<div class="presentationBottom">
<div class="presentationLeftBottom">
</div><!-- end of presentationLeftBottom -->
<div class="rbNipple"></div>
</div><!-- end of presentationBottom -->
</div><!-- end of presentationTop -->
</div><!-- end of reusableBox -->
<div id="bar" class="rbSource">
<p>Reusable balloon, built with JavaScript.
<code>
makeWeb2Box(someId (string), width (integer), top (integer), left (integer), [hasPointer (boolean), pointerPosition (integer)])
</code>
Turns the hidden div named 'someId' into a popup,
with or without a pointer (the default is no pointer).
If a pointer is specified, optionally set the left position
of the pointer image (the default is set in the CSS).
</p>
</div>
<div id="jsBox" class="rbSource">
<p>This is a box (not a balloon, because the pointer is omitted). This box has been built with JavaScript.</p>
</div>
</body>
</html>
Category: Uncategorized |
Tags: alistapart, css, DOM, example, html, javascript, layout, nonsemantic, slidingdoors, standards, template
C – Example Buffer OverFlow
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
char *buffer1 = (char *)calloc(5, sizeof(char));
char *buffer2 = (char *)calloc(15, sizeof(char));
char *tmp;
strcpy(buffer2, "ls -a --color");
strcpy(buffer1, argv[1]);
// Indirizzi di memoria...
printf("%p <-- buffer1
", buffer1);
printf("%p <-- buffer2
", buffer2);
printf("
");
// Stampa indirizzi...
printf("Start code....
");
tmp=buffer1;
while(tmp<buffer2+15)
{
printf("%p: %c (0x%x)
", tmp, *tmp, *(unsigned int *)tmp);
tmp++;
}
printf("
");
system(buffer2);
return 0;
}
perl google soap example
#!/usr/bin/perl
use SOAP::Lite;
use strict;
use warnings;
@ARGV == 2 or die "Usage: google <query> <number of results 1-10>
";
my $key='OS7mOjxQFHIztxIYU9yb8y3ibYgY4w2o';
my($query, $maxResults) = @ARGV;
my @params = ($key, $query, 0, $maxResults, 0, '', 0, '', 'latin1', 'latin1');
my $result = SOAP::Lite->service("file:GoogleSearch.wsdl")->doGoogleSearch(@params);
print "Result:
";
print join "
", map( { qq{$_->{URL}} } @{$result->{resultElements}} );
Here is the Google include file:
<?xml version="1.0"?>
<!-- WSDL description of the Google Web APIs.
The Google Web APIs are in beta release. All interfaces are subject to
change as we refine and extend our APIs. Please see the terms of use
for more information. -->
<!-- Revision 2002-08-16 -->
<definitions name="GoogleSearch"
targetNamespace="urn:GoogleSearch"
xmlns:typens="urn:GoogleSearch"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns="http://schemas.xmlsoap.org/wsdl/">
<!-- Types for search - result elements, directory categories -->
<types>
<xsd:schema xmlns="http://www.w3.org/2001/XMLSchema"
targetNamespace="urn:GoogleSearch">
<xsd:complexType name="GoogleSearchResult">
<xsd:all>
<xsd:element name="documentFiltering" type="xsd:boolean"/>
<xsd:element name="searchComments" type="xsd:string"/>
<xsd:element name="estimatedTotalResultsCount" type="xsd:int"/>
<xsd:element name="estimateIsExact" type="xsd:boolean"/>
<xsd:element name="resultElements" type="typens:ResultElementArray"/>
<xsd:element name="searchQuery" type="xsd:string"/>
<xsd:element name="startIndex" type="xsd:int"/>
<xsd:element name="endIndex" type="xsd:int"/>
<xsd:element name="searchTips" type="xsd:string"/>
<xsd:element name="directoryCategories" type="typens:DirectoryCategoryArray"/>
<xsd:element name="searchTime" type="xsd:double"/>
</xsd:all>
</xsd:complexType>
<xsd:complexType name="ResultElement">
<xsd:all>
<xsd:element name="summary" type="xsd:string"/>
<xsd:element name="URL" type="xsd:string"/>
<xsd:element name="snippet" type="xsd:string"/>
<xsd:element name="title" type="xsd:string"/>
<xsd:element name="cachedSize" type="xsd:string"/>
<xsd:element name="relatedInformationPresent" type="xsd:boolean"/>
<xsd:element name="hostName" type="xsd:string"/>
<xsd:element name="directoryCategory" type="typens:DirectoryCategory"/>
<xsd:element name="directoryTitle" type="xsd:string"/>
</xsd:all>
</xsd:complexType>
<xsd:complexType name="ResultElementArray">
<xsd:complexContent>
<xsd:restriction base="soapenc:Array">
<xsd:attribute ref="soapenc:arrayType" wsdl:arrayType="typens:ResultElement[]"/>
</xsd:restriction>
</xsd:complexContent>
</xsd:complexType>
<xsd:complexType name="DirectoryCategoryArray">
<xsd:complexContent>
<xsd:restriction base="soapenc:Array">
<xsd:attribute ref="soapenc:arrayType" wsdl:arrayType="typens:DirectoryCategory[]"/>
</xsd:restriction>
</xsd:complexContent>
</xsd:complexType>
<xsd:complexType name="DirectoryCategory">
<xsd:all>
<xsd:element name="fullViewableName" type="xsd:string"/>
<xsd:element name="specialEncoding" type="xsd:string"/>
</xsd:all>
</xsd:complexType>
</xsd:schema>
</types>
<!-- Messages for Google Web APIs - cached page, search, spelling. -->
<message name="doGetCachedPage">
<part name="key" type="xsd:string"/>
<part name="url" type="xsd:string"/>
</message>
<message name="doGetCachedPageResponse">
<part name="return" type="xsd:base64Binary"/>
</message>
<message name="doSpellingSuggestion">
<part name="key" type="xsd:string"/>
<part name="phrase" type="xsd:string"/>
</message>
<message name="doSpellingSuggestionResponse">
<part name="return" type="xsd:string"/>
</message>
<!-- note, ie and oe are ignored by server; all traffic is UTF-8. -->
<message name="doGoogleSearch">
<part name="key" type="xsd:string"/>
<part name="q" type="xsd:string"/>
<part name="start" type="xsd:int"/>
<part name="maxResults" type="xsd:int"/>
<part name="filter" type="xsd:boolean"/>
<part name="restrict" type="xsd:string"/>
<part name="safeSearch" type="xsd:boolean"/>
<part name="lr" type="xsd:string"/>
<part name="ie" type="xsd:string"/>
<part name="oe" type="xsd:string"/>
</message>
<message name="doGoogleSearchResponse">
<part name="return" type="typens:GoogleSearchResult"/>
</message>
<!-- Port for Google Web APIs, "GoogleSearch" -->
<portType name="GoogleSearchPort">
<operation name="doGetCachedPage">
<input message="typens:doGetCachedPage"/>
<output message="typens:doGetCachedPageResponse"/>
</operation>
<operation name="doSpellingSuggestion">
<input message="typens:doSpellingSuggestion"/>
<output message="typens:doSpellingSuggestionResponse"/>
</operation>
<operation name="doGoogleSearch">
<input message="typens:doGoogleSearch"/>
<output message="typens:doGoogleSearchResponse"/>
</operation>
</portType>
<!-- Binding for Google Web APIs - RPC, SOAP over HTTP -->
<binding name="GoogleSearchBinding" type="typens:GoogleSearchPort">
<soap:binding style="rpc"
transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="doGetCachedPage">
<soap:operation soapAction="urn:GoogleSearchAction"/>
<input>
<soap:body use="encoded"
namespace="urn:GoogleSearch"
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</input>
<output>
<soap:body use="encoded"
namespace="urn:GoogleSearch"
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</output>
</operation>
<operation name="doSpellingSuggestion">
<soap:operation soapAction="urn:GoogleSearchAction"/>
<input>
<soap:body use="encoded"
namespace="urn:GoogleSearch"
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</input>
<output>
<soap:body use="encoded"
namespace="urn:GoogleSearch"
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</output>
</operation>
<operation name="doGoogleSearch">
<soap:operation soapAction="urn:GoogleSearchAction"/>
<input>
<soap:body use="encoded"
namespace="urn:GoogleSearch"
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</input>
<output>
<soap:body use="encoded"
namespace="urn:GoogleSearch"
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</output>
</operation>
</binding>
<!-- Endpoint for Google Web APIs -->
<service name="GoogleSearchService">
<port name="GoogleSearchPort" binding="typens:GoogleSearchBinding">
<soap:address location="http://api.google.com/search/beta2"/>
</port>
</service>
</definitions>
ruby ascii golf example
#!/usr/bin/env ruby
$><<"e[2J";s,o,f,c,u=20,"#"," ";b,m=(z=0..s).map{z.map{(rand<0.3)?o:f}},[-1,0,1]*3;until c==b;c=b.map{|z|z.dup};$><<"e[H"<<b.map{|x|x*f}*"";s.times{|i|s.times{|e|n=(m.sort.zip(m)-[[0,0]]).select{|x,z|o==(c[i+x]||[])[e+z]}.size;n!=2?b[i][e]=n==3?o:f:f}};sleep 0.2;end
Write to file
#!/usr/bin/python
filename = "test.txt"
print "Writing to file: %s" % filename
file = open(filename, 'w')
file.write("This is the new content of test.txt <img src='http://www.snippetsmania.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> ")
file.close()
LWP request example
#!/usr/bin/perl
# load LWP library:
use LWP::UserAgent;
use HTML::Parse;
# define a URL
my $url = 'http://www.jonasjohn.de';
# create UserAgent object
my $ua = new LWP::UserAgent;
# set a user agent (browser-id)
# $ua->agent('Mozilla/5.5 (compatible; MSIE 5.5; Windows NT 5.1)');
# timeout:
$ua->timeout(15);
# proceed the request:
my $request = HTTP::Request->new('GET');
$request->url($url);
my $response = $ua->request($request);
#
# responses:
#
# response code (like 200, 404, etc)
my $code = $response->code;
# headers (Server: Apache, Content-Type: text/html, ...)
my $headers = $response->headers_as_string;
# HTML body:
my $body = $response->content;
# print the website content:
# print $body;
# do some parsing:
my $parsed_html = HTML::Parse::parse_html($body);
for (@{ $parsed_html->extract_links(qw(a body img)) }) {
# extract all links (a, body, img)
my ($link) = @$_;
# print link:
print $link . "
";
}
soundex examples
$word2find = 'stupid';
$words = array(
'stupid',
'stu and pid',
'hello',
'foobar',
'stpid',
'supid',
'stuuupid',
'sstuuupiiid',
);
while(list($id, $str) = each($words)){
$soundex_code = soundex($str);
if (soundex($word2find) == $soundex_code){
print '"' . $word2find . '" sounds like ' . $str;
}
else {
print '"' . $word2find . '" sounds not like ' . $str;
}
print "
";
}
/*
result:
"stupid" sounds like stupid
"stupid" sounds not like stu and pid
"stupid" sounds not like hello
"stupid" sounds not like foobar
"stupid" sounds like stpid
"stupid" sounds not like supid
"stupid" sounds like stuuupid
"stupid" sounds like sstuuupiiid
*/