Tag Archive for web

Haproxy load-balanced web cluster with different backends through acl’s

# HTTP web cluster
frontend cluster_http
bind    :80
mode    http
option  forwardfor
acl content_php path_end .php
use_backend dynamic_cluster_http if content_php
default_backend static_cluster_http

# Static cluster serving every file EXCEPT those ending with .php
backend static_cluster_http
mode 	http
option  forwardfor
balance source
option  httpclose
option  httpchk HEAD / HTTP/1.0
server  staticweb1 192.168.0.100:80 weight 1 check inter 1000 rise 5 fall 1
server  staticweb2 192.168.0.101:80 weight 1 check inter 1000 rise 5 fall 1

# Dynamic cluster serving files ending with .php
backend dynamic_cluster_http
mode    http
option  forwardfor
balance source
option  httpclose
option  httpchk HEAD / HTTP/1.0
server  dynweb1 192.168.0.102:80 weight 1 check inter 1000 rise 5 fall 1
server  dynweb2 192.168.0.103:80 weight 1 check inter 1000 rise 5 fall 1

source

Get HTML from a URI

// Taken from C# 3.0 Cookbook
public static string GetHtmlFromUri(string resource)
{
string html = string.Empty;
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(resource);
using (HttpWebResponse resp = (HttpWebResponse)req.GetResponse())
{
bool isSuccess = (int)resp.StatusCode < 299 && (int)resp.StatusCode >= 200;
if (isSuccess)
{
using (StreamReader reader = new StreamReader(resp.GetResponseStream()))
{
html = reader.ReadToEnd();
}
}
}
return html;
}

source

Easy Margin Helper Classes

/******* Margin Helpers *******/
/*		Margin-All					*/
.m-0 { margin: 0px; } .m-5 { margin: 5px; } .m-10 { margin: 10px; } .m-15 { margin: 15px; } .m-20 { margin: 20px; } .m-25 { margin: 25px; } .m-30 { margin: 30px; } .m-35 { margin: 35px; }
/*		Margin-left					*/
.ml-3  { margin-left: 3px; } .ml-5  { margin-left: 5px; } .ml-10 { margin-left: 10px; } .ml-15 { margin-left: 15px; } .ml-20 { margin-left: 20px; } .ml-25 { margin-left: 25px; } .ml-30 { margin-left: 30px; }
/*		Margin-right				*/
.mr-3  { margin-right: 3px; } .mr-5  { margin-right: 5px; } .mr-10 { margin-right: 10px; } .mr-15 { margin-right: 15px; } .mr-20 { margin-right: 20px; } .mr-25 { margin-right: 25px; } .mr-30 { margin-right: 30px; }
/*		Margin-Horizontal			*/
.mh-5 	{ margin-left: 5px; margin-right: 5px; } .mh-10 { margin-left: 10px; margin-right: 10px; } .mh-15 { margin-left: 15px; margin-right: 15px; } .mh-20 { margin-left: 20px; margin-right: 20px; } .mh-25 { margin-left: 25px; margin-right: 25px; } .mh-30 { margin-left: 30px; margin-right: 30px }
/*		Margin Vertical				*/
.mv-5 	{ margin: 5px 0; } .mv-10 { margin: 10px 0; } .mv-15 { margin: 15px 0; } .mv-20 { margin: 20px 0; } .mv-25 { margin: 25px 0px; } .mv-25 { margin:30px 0; }
/*		Margin-bottom			*/
.mt-3  { margin-bottom: 3px; } .mt-5  { margin-bottom: 5px; } .mt-10 { margin-bottom: 10px; } .mt-15 { margin-bottom: 15px; } .mt-20 { margin-bottom: 20px; } .mt-25 { margin-bottom: 25px; } .mt-30 { margin-bottom: 30px; }
/*		Margin-bottom		*/
.mb-3  { margin-bottom: 3px; } .mb-5  { margin-bottom: 5px; } .mb-10 { margin-bottom: 10px; } .mb-15 { margin-bottom: 15px; } .mb-20 { margin-bottom: 20px; } .mb-25 { margin-bottom: 25px; } .mb-30 { margin-bottom: 30px; }

source

Thesis – Remove Comments Closed (CSS)

.custom .comments_closed p {display: none ;}

source

Image directory index

<? $title = htmlspecialchars("Guy Fawkes Nights at EBI Campus & Cambridge 4-5.11.2008"); ?>
<html>
<head>
<title><?= $title ?></title>
<style type="text/css">
body { background: #666666;color: #cccccc;font-family: tahoma, verdana, sans-serif;padding: 30px; }
img { border: 1px solid #cccccc;margin-right: 30px;vertical-align:top; }
h1 { font-size: 30pt;font-weight: bold;margin-bottom:50px; }
div { font-size: 10pt; }
span { font-size: 30pt;font-weight: bold;font-family: impact,tahoma,sans-serif;color: #888888; }
a:link,a:hover,a:active,a:visited { color: #cccccc; text-decoration:underline}
</style>
</head>
<body>
<h1><?= $title ?></h1>
<p><a href="../">back to list</a></p>
<?
// just a comment to test and remove

$cwd = opendir('.');
if(!$cwd) die("can't open dir!");

$desc = array();
if(file_exists('descript.ion'))
foreach(file('descript.ion') as $line)
if(preg_match('/^(S+)s+(.*?)s*$/', $line, $d))
$desc[$d[1]] = $d[2];

$images = array();
while($file = readdir($cwd))
{
if(preg_match('/.(jpe?g|gif|png)$/i', $file) && is_readable($file))
{
list($width, $height, $type) = getimagesize($file);
if($width && $height)
{
$images[$file] = array($width, $height);
}
}
}

$names = array_keys($images);
sort($names);
$k = 0;
foreach($names as $img)
{
$i = $images[$img];
?>
<p><img src="<?=$img?>" width="<?=$i[0]?>" height="<?=$i[1]?>" alt=""><span><?=++$k?></span><div><?=htmlspecialchars($desc[$img])?></div></p>
<?
}
?>
</body>
</html>

source

zanox Web Services – Contextual Product Search Widget for blogger.com

<ul id="zxAdList"></ul>

<script type="text/javascript">

function addScript(url) {
var script = document.createElement('script');
script.src = url + '&t=' + new Date().getMinutes();
script.type = 'text/javascript';
document.getElementsByTagName('head')[0].appendChild(script);
}

function productSearch(version, applicationid, adspace, region, programs, minPrice, maxPrice, category, page, items, q, callback) {
var url = 'http://api.zanox.com/json';
if (version) url+= '/' + version;
url += '/products?applicationid=' + applicationid;
if (adspace) url += '&adspace=' + adspace;
if (region) url += '&region=' + region;
if (programs) url += '&programs=' + programs;
if (category) url += '&category=' + category;
if (page) url += '&page=' + page;
if (items) url += '&items=' + items;
if (minPrice) url += '&minPrice=' + minPrice;
if (maxPrice) url += '&maxPrice=' + maxPrice;
if (callback) url += '&callback=' + callback;
if (q) url += '&q=' + q;
addScript(url);
}

function renderLinkListItem(content, link, itemContainer) {
var li = document.createElement("li");
li.innerHTML = '<a href="' + link + '">' + content + '</a>';
itemContainer.appendChild(li);
}

function handler(data) {
if (data.productsResult) {
var productItems = data.productsResult.productItem;
var zxAdList = document.getElementById('zxAdList'); //ID of a UL HTML element

for (var i = 0; i < productItems.length; i++) {
var productItem = productItems[i];
var link = '';
if (productItem.url.adspace instanceof Array) {
// select tracking link related to the first Adspace
link = productItem.url.adspace[0].$;
}
else {
link = productItem.url.adspace.$;
}
var content = productItem.name + ' bei ' + productItem.program.$ + ' für ' + productItem.price + ' ' + productItem.currency;
renderLinkListItem(content, link, zxAdList);
}
}

}

var zx_query = document.getElementsByTagName('h3').item(0).getElementsByTagName('a').item(0).innerHTML;

//contextual product search parameters: version, applicationid, adspace, region, programs, minPrice, maxPrice, category, page, items, q, callback

productSearch(null, 'BE94C4947839E8AB4D67', null, 'de', '660', null, null, null, 0, 5, zx_query, 'handler');

</script>

source

SKOR PHP Template

<?php
require_once(dirname(__FILE__).DIRECTORY_SEPARATOR.'class_template.php');
require_once(dirname(__FILE__).DIRECTORY_SEPARATOR.'class_section.php');

/**
* class section "Intro" *
**/
$sec        =  new section();
$sec->dir    =  dirname(__FILE__).DIRECTORY_SEPARATOR;
$sec->html    = 'section.html';
$sec->read();

/**
* class section "Hello world" *
**/
$sec->assign_section('Head');
$sec->assign('HALLO','Hi World');
$sec->assign_section('Example');

/**
* class section "Alternating table rows" *
**/
$tbody = '';
for($i = 0; $i <= 5; $i++){

$sec->assign('COUNTER', $i);

if(is_int($i/2)){
$tbody .= $sec->fetch('RowGreen');
}else{
$tbody .= $sec->fetch('RowRed');
}
}
$sec->assign('TBODY',$tbody);
$sec->assign_section('Table');

/**
* class section "Nested sections with two children" *
**/
$sec->assign('PLACEHOLDER','placeholder');
$sec->assign('MOTHER',$sec->fetch('ChildOne') . $sec->fetch('ChildTwo'));
$sec->assign_section('Mother');

/**
* class section footer" *
**/
$sec->assign_section('End');
?>

source

Return HTML from a Web page

Public Function GetHTML(ByVal sURL As String, ByVal e As Integer) As String
Dim oHttpWebRequest As System.Net.HttpWebRequest
Dim oStream As System.IO.Stream
Dim sChunk As String
oHttpWebRequest = (System.Net.HttpWebRequest.Create(sURL))
Dim oHttpWebResponse As System.Net.WebResponse = oHttpWebRequest.GetResponse()
oStream = oHttpWebResponse.GetResponseStream
sChunk = New System.IO.StreamReader(oStream).ReadToEnd()
oStream.Close()
oHttpWebResponse.Close()
If e = 0 Then
Return Server.HtmlEncode(sChunk)
Else
Return Server.HtmlDecode(sChunk)
End If
End Function

source

zanox Web Services contextual Product Search

function addScript(url) {
var script = document.createElement("script");
script.src = url + '&t='+new Date().getMinutes();
script.type = "text/javascript";
document.getElementsByTagName("head")[0].appendChild(script);
}

function productSearch(version, applicationid, adspace, region, programs, minPrice, maxPrice, category, page, items, q, callback) {
var url = 'http://api.zanox.com/json/' + version + '/products?applicationid=' + applicationid;
if (adspace) url += '&adspace=' + adspace;
if (region) url += '&region=' + region;
if (programs) url += '&programs=' + programs;
if (category) url += '&category=' + category;
if (page) url += '&page=' + page;
if (items) url += '&items=' + items;
if (minPrice) url += '&minPrice=' + minPrice;
if (maxPrice) url += '&maxPrice=' + maxPrice;
if (callback) url += '&callback=' + callback;
if (q) url += '&q=' + q;
addScript(url);
}

source

Convert ISBN file names to BibTeX records

#!/usr/bin/env perl

use strict;
use warnings;

use Encoding "utf8";
use Text::BibTeX;
use WebService::ISBNDB::API::Books;
use Getopt::Long;
use Pod::Usage;

my %options;
GetOptions('usage|?'  => $options{usage},
'h|help' 	=> $options{help}
);
pod2usage(1) if $options{usage};
pod2usage(-verbose => 2) if $options{help};

my $api_key = $ENV{ISBNDB_KEY} || 'TMDKWJSX';

my $dir = shift || '.';
my $file = shift || '&STDOUT';
my $bib = Text::BibTeX::File->new('>'.$file);

opendir my $dh, $dir
or die "Cannot open $dir: $!
";
my @files =  grep { -f && m{/d{9}[x|d].pdf$}i }
map {"$dir/$_"}
readdir $dh;

foreach my $file (@files) {

# extract isbn from file name
my $isbn = $file =~ /(d{9}[x|d]).pdf$/i ? $1 : '0000000000' ;
# check database for isbn number, loop if failed
my $book = WebService::ISBNDB::API::Books->find( { api_key => $api_key, isbn => $isbn } );
next unless $book;

# set new bibtex entry
my $entry = new Text::BibTeX::Entry;
$entry->set_metatype(BTE_REGULAR);
$entry->set_type('book');
$entry->set_key($isbn);

# set title field
$entry->set( 'title', $book->get_longtitle || $book->get_title );

# set author or editor field
my $authors = $book->get_authors_text;
# some clean-up
$authors =~ s/^by //;
$authors =~ s/,$//;
$authors =~ s/,s+/ and /g;
$authors =~ s/;s+/ and /g;
# authors or editors ?
if ( $authors =~ /^s*[?edited bys+]?(.*)$/i ) {
(my $editors = $1) =~ s/with/and/;
$entry->set('editor', $editors);
}
elsif ( $authors =~ /(Editor)/i ) {
$authors =~ s/s*(Editor)//gi;
}
else {
$entry->set('author', $authors);
}

# parse publisher and edition fields for publisher and year data
if ( $book->get_publisher_text =~ m/^(.*?),s+c?(d{4}).?$/ ) {
$entry->set( 'publisher', $1 ) ;
$entry->set( 'year', $2 );

}
else {
$entry->set( 'publisher', $book->get_publisher_text ) ;
if ( $book->get_edition_info =~ m/(d{4})/ ) {
$entry->set( 'year', $1 );
}
}

# miscellaneous fields
my $notes = $book->get_notes;
$entry->set( 'notes', $notes ) if $notes ;
my $abstract = $book->get_summary;
$entry->set( 'abstract', $abstract ) if $abstract ;

$entry->set( 'local-url', $file);

$entry->write($bib);

# sleep 2;
}

__END__

=head1 NAME

isbn2bibtex.pl - Convert ISBN file names to BibTeX records

=head1 SYNOPSIS

isbn2bibtex.pl [-? | --help] | [directory] [outfile.bib]

=head1 DESCRIPTION

Scans a directory for PDF files whose name are ISBN-10 identifiers,
fetches the corresponding book's data from isbndb.com, parses data
fields to get rid of inconsistencies, and finally, outputs a bibtex
file with all fields set accordingly.

-?             print usage
-h --help      verbose help message

If no directory is given, scans the current directory. Outputs result
to STDOUT, unless a second argument is given.

An API key is required to access isbndb.com services. You can either
paste it in the source code or set the environment variable ISBNDB_KEY.

=head1 LICENSE

Free to use and modifiy, same terms as Perl itself.

=head1 AUTHOR

i-blis, I<i-blis yandex ru>.

=cut

source