<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Tutorial &#8211; Blackbams Blog</title>
	<atom:link href="https://blog.blackbam.at/tag/tutorial/feed/" rel="self" type="application/rss+xml" />
	<link>https://blog.blackbam.at</link>
	<description>development - digital arts - internet</description>
	<lastBuildDate>Thu, 10 Sep 2020 08:59:21 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.8.1</generator>
	<item>
		<title>From STUPID to SOLID Code! &#8211; recommended article on best practice in software development</title>
		<link>https://blog.blackbam.at/2020/09/10/from-stupid-to-solid-code-recommended-article-on-best-practice-in-software-development/</link>
					<comments>https://blog.blackbam.at/2020/09/10/from-stupid-to-solid-code-recommended-article-on-best-practice-in-software-development/#respond</comments>
		
		<dc:creator><![CDATA[Blackbam]]></dc:creator>
		<pubDate>Thu, 10 Sep 2020 08:59:21 +0000</pubDate>
				<category><![CDATA[Software Development]]></category>
		<category><![CDATA[best practice]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[SOLID]]></category>
		<category><![CDATA[STUPID]]></category>
		<category><![CDATA[Tutorial]]></category>
		<guid isPermaLink="false">https://blog.blackbam.at/?p=2419</guid>

					<description><![CDATA[Today I want to share an article which is 7 years old but still 100% accurate. It shows the common mistakes in software development and the best practices about how to avoid those mistakes. Short summary &#8211; do not do STUPID code: Singleton Tight Coupling Untestability Premature Optimization Indescriptive Naming Duplication Do SOLID code: Single [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>Today I want to share an article which is 7 years old but still 100% accurate. It shows the common mistakes in software development and the best practices about how to avoid those mistakes.</p>
<p>Short summary &#8211; do not do <strong>STUPID</strong> code:</p>
<ul>
<li><strong>S</strong>ingleton</li>
<li><strong>T</strong>ight Coupling</li>
<li><strong>U</strong>ntestability</li>
<li><strong>P</strong>remature Optimization</li>
<li><strong>I</strong>ndescriptive Naming</li>
<li><strong>D</strong>uplication</li>
</ul>
<p>Do <strong>SOLID</strong> code:</p>
<ul>
<li><strong>S</strong>ingle Responsibility Principle</li>
<li><strong>O</strong>pen/Closed Principle</li>
<li><strong>L</strong>iskov Substitution Principle</li>
<li><strong>I</strong>nterface Segregation Principle</li>
<li><strong>D</strong>ependency Inversion Principle</li>
</ul>
<p>Read the full article here: <a href="https://williamdurand.fr/2013/07/30/from-stupid-to-solid-code/">https://williamdurand.fr/2013/07/30/from-stupid-to-solid-code/</a></p>
<p><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fblog.blackbam.at%2F2020%2F09%2F10%2Ffrom-stupid-to-solid-code-recommended-article-on-best-practice-in-software-development%2F&#038;title=From%20STUPID%20to%20SOLID%20Code%21%20%E2%80%93%20recommended%20article%20on%20best%20practice%20in%20software%20development" data-a2a-url="https://blog.blackbam.at/2020/09/10/from-stupid-to-solid-code-recommended-article-on-best-practice-in-software-development/" data-a2a-title="From STUPID to SOLID Code! – recommended article on best practice in software development"><img src="https://static.addtoany.com/buttons/share_save_120_16.png" alt="Share"></a></p>]]></content:encoded>
					
					<wfw:commentRss>https://blog.blackbam.at/2020/09/10/from-stupid-to-solid-code-recommended-article-on-best-practice-in-software-development/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Laravel in five minutes: A super short crash course for the awesome PHP framework (principles and core functionalities)</title>
		<link>https://blog.blackbam.at/2019/07/08/laravel-in-five-minutes-a-super-short-crash-course-for-the-awesome-php-framework-principles-and-core-functionalities/</link>
					<comments>https://blog.blackbam.at/2019/07/08/laravel-in-five-minutes-a-super-short-crash-course-for-the-awesome-php-framework-principles-and-core-functionalities/#respond</comments>
		
		<dc:creator><![CDATA[Blackbam]]></dc:creator>
		<pubDate>Mon, 08 Jul 2019 19:44:35 +0000</pubDate>
				<category><![CDATA[Frameworks]]></category>
		<category><![CDATA[Laravel]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[crash course]]></category>
		<category><![CDATA[dependency injection]]></category>
		<category><![CDATA[for dummies]]></category>
		<category><![CDATA[framework]]></category>
		<category><![CDATA[middleware]]></category>
		<category><![CDATA[Tutorial]]></category>
		<guid isPermaLink="false">https://blog.blackbam.at/?p=2384</guid>

					<description><![CDATA[Laravel super short five minutes crash course - an overview of what it is, the core concepts and the core functionalities.]]></description>
										<content:encoded><![CDATA[<p>For understanding this Q&amp;A style tutorial you should have basic knowledge about PHP programming and frameworks. You do not have to know Laravel yet. For the real documentation just learn <a href="https://laravel.com/docs/">https://laravel.com/docs/</a> &#8211; most information in this tutorial is just a real short summary of the documentation. It is useful though if you have to learn about what Laravel is and what the most important concepts and components are.</p>
<p>&nbsp;</p>
<p><strong>Why should I even use Laravel?</strong></p>
<p>Because it is a super clean, easy to use PHP framework. My personal experience (this is subjective) told me that it is way easier to understand than the whole Symfony framework (Laravel is built on Symfony) or the Zend Frameworks. Symfony and Zend are both great frameworks, for sure, but Laravel offers you <em>simplicity</em>.</p>
<p>Laravel enables you to use best practice coding techniques for object-oriented programming. It comes with a powerful set of features for building solid web applications and assists you with solving common as well as complex problems.</p>
<p>&nbsp;</p>
<p><strong>Why shall Laravel be used with the newest PHP version (best will be the upcoming PHP 7.4)?</strong></p>
<p>Laravel makes heavy use of modern features within the PHP language. It is completely object oriented and uses e.g. typed input parameters which came with PHP 7.</p>
<p>The real great thing about PHP 7.4 is that it offers <strong>typed properties</strong>, <strong>covariant returns</strong> (more generic in subclass) and <strong>contravariant input parameters</strong> (more specific in subclass). This is extremely powerful (you should read more about it)!</p>
<p><strong> </strong></p>
<p><strong>What is Dependency Injection?</strong></p>
<p>Definition (Wikipedia): “In software engineering, dependency injection is a technique whereby one object supplies the dependencies of another object. A &#8220;dependency&#8221; is an object that can be used, for example a service. Instead of a client specifying which service it will use, something tells the client what service to use. The &#8220;injection&#8221; refers to the passing of a dependency (a service) into the object (a client) that would use it. The service is made part of the client&#8217;s state. Passing the service to the client, rather than allowing a client to build or find the service, is the fundamental requirement of the pattern.</p>
<p>The intent behind dependency injection is to achieve Separation of Concerns of construction and use of objects. This can increase readability and code reuse.</p>
<p>Dependency injection is one form of the broader technique of inversion of control. The client delegates the responsibility of providing its dependencies to external code (the injector). The client is not allowed to call the injector code; it is the injecting code that constructs the services and calls the client to inject them. This means the client code does not need to know about the injecting code, how to construct the services or even which actual services it is using; the client only needs to know about the intrinsic interfaces of the services because these define how the client may use the services. This separates the responsibilities of use and construction.”</p>
<p>That means that an object either is provided with another required object within its constructor or it just specifies some interface which is used for type hinting in constructors or methods.</p>
<p>The purpose of this is to get rid of dependencies and to achieve loose coupling (and high cohesion).</p>
<p>&nbsp;</p>
<p><strong>What is a Service Container and what is the Laravel Service Container doing?</strong></p>
<p>A Service Container (or dependency injection container) is simply a PHP object that manages the instantiation of services (i.e. objects). The Service Container in Laravel is a Dependency Injection Container and a Registry for the application. The advantages of using a Service Container over creating manually your objects are.</p>
<p>It is often called with App::bind App:make etc.</p>
<p>The service provider is creating concrete classes automatically when required.</p>
<p>Class dependencies can be managed on object creation and it is used as a registry.</p>
<p>Laravel does this with binding certain services to the App:</p>
<p><code>$this-&gt;app-&gt;bind('FooService', \App\Services\FooService::class);</code></p>
<p>Essentially we are telling Laravel: “Hey store this object in your bag of tricks and label it as FooService”. Remember to always bind your services within the register method of your service providers.</p>
<p>There are also events in the service container where somebody can register to.</p>
<p><strong> </strong></p>
<p><strong>What is a Service Provider?</strong></p>
<p>Core part of a Laravel application, resides in Providers directory. Has usually a special purpose like e.g. Authentication, Translation, ….</p>
<p>Service providers are usually registered on application bootstrap. All service providers are registered in <strong>app/config.php.</strong></p>
<p>A service provider has a register and a boot method. The register method is called early and is for registering with the Service Container, the boot method is called after all Services has been registered and therefore you can use all Service Container within it.</p>
<p>&nbsp;</p>
<p><strong>What is „type hinting“?</strong></p>
<p>Methods / functions with typed input parameters (optional in PHP).</p>
<p>&nbsp;</p>
<p><strong>What is (dynamic) binding in Laravel?</strong></p>
<p>Laravel usually means binding a service provider to the service container. Almost all service container bindings will be registered within service providers.</p>
<p>&nbsp;</p>
<p><strong>What is middleware?</strong></p>
<p>A layer between a client request from the frontend and a resource (data) in the backend. Therefore the logical part oft he backend which glues certain programs / part of a program together. It simplifies backend resource requests.</p>
<p>Middleware also serves the purpose of load balancing (distributing requests), concurrency, securring the backend,  …</p>
<p>Laravel offers many Middleware objects. One middleware for instance is for authentication, but you can also use middleware for certain headers for instance.</p>
<p>&nbsp;</p>
<p><strong>What is a Facade?</strong></p>
<p>A Facade is a programming design pattern. It usually offers <strong><em>a simplified standardized interface to a certain set of sub-systems</em></strong>.</p>
<p>In Laravel: Facades provide a &#8220;static&#8221; interface to classes that are available in the application&#8217;s service container. Laravel ships with many facades which provide access to almost all of Laravel&#8217;s features. Laravel facades serve as &#8220;static proxies&#8221; to underlying classes in the service container, providing the benefit of a terse, expressive syntax while maintaining more testability and flexibility than traditional static methods.</p>
<p>Examples for Facades in Laravel are calls to App::, Auth::, DB::, Cookie:: …</p>
<p>Facades can be useful because they are not required in class constructors, but they can also make an application complicated to maintain in case they get to large.</p>
<p>&nbsp;</p>
<p><strong>What is a Contract in Laravel?</strong></p>
<p>Laravel&#8217;s Contracts are a set of interfaces that define the core services provided by the framework. The Illuminate\Contracts\Queue\Queue contract i.e. defines the methods needed for queueing jobs, while the Illuminate\Contracts\Mail\Mailer contract defines the methods needed for sending e-mail.</p>
<p>Contracts are often imported with the use keyword and used (e.g. in the constructor or some method). It is easy to write alternative Contract implementations and therefore they can be replaced easily.</p>
<p>&nbsp;</p>
<p><strong>What is PHP artisan?</strong></p>
<p>PHP artisan is command line tool that makes your life easier. In fact, very much easier while working with Laravel. If you know about any MVC framework, you would know what I&#8217;m about to say, it can create models, controllers, seeders, migrations and many other things with minimum (or maximum) boilerplate code. It can also start a server and can do many other things.</p>
<p><strong> </strong></p>
<p><strong>How is routing working in Laravel?</strong></p>
<p>Usually defined in routes/web.php (for API routs for instance routes/api.php is used). Basically defined with the Route Facade which offers the common HTTP methods and a callback function. Routes have certain rules for parameters (also wildcard), can be grouped, …</p>
<p>&nbsp;</p>
<p><strong>What are Controllers in Laravel?</strong></p>
<p>Handling all requests within route files can be clumsy. Controllers can do the most important calls to the model/business layer and return everything properly.</p>
<p>&nbsp;</p>
<p><strong>What is the Request/Response object doing?</strong></p>
<p>The service container can automatically inject Request/Response objects (e.g. into a certain Controller). It contains info like e.g. input parameters, cookies, and does some sanitation on it.</p>
<p>Routes and Controllers usually should return response objects or views. You can add headers and cookies, create downloads, define the output, …</p>
<p>&nbsp;</p>
<p><strong>How are views in Laravel working?</strong></p>
<p>In most projects Blade is used as a template engine. The views are built with html and contain output injected by Blade.</p>
<p>&nbsp;</p>
<p><strong>How is validation in Laravel working?</strong></p>
<p>Laravel has a powerful set of validation rules which can be performed on inputs (e.g. in Controllers).</p>
<p>&nbsp;</p>
<p><strong>How is Laravel to databases?</strong></p>
<p>Laravel usually uses the Eloquent ORM mapper. It simplifies database communication and SQL statements with certain methods. It offers a query builder which simplifies queries.</p>
<p>&nbsp;</p>
<p><strong>How are migrations and seeding working in Laravel?</strong></p>
<p>Migrations are like version control for your database, allowing your team to easily modify and share the application&#8217;s database schema. Migrations are typically paired with Laravel&#8217;s schema builder to easily build your application&#8217;s database schema. If you have ever had to tell a teammate to manually add a column to their local database schema, you&#8217;ve faced the problem that database migrations solve.</p>
<p>The Laravel Schema facade provides database agnostic support for creating and manipulating tables across all of Laravel&#8217;s supported database systems.</p>
<p>Laravel has a Seeder for seeding applications with defined or random data which is really helpful during development.</p>
<p>&nbsp;</p>
<p>Be free to critizise this tutorial. Improvement ideas are always welcome! 😉 </p>
<p><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fblog.blackbam.at%2F2019%2F07%2F08%2Flaravel-in-five-minutes-a-super-short-crash-course-for-the-awesome-php-framework-principles-and-core-functionalities%2F&#038;title=Laravel%20in%20five%20minutes%3A%20A%20super%20short%20crash%20course%20for%20the%20awesome%20PHP%20framework%20%28principles%20and%20core%20functionalities%29" data-a2a-url="https://blog.blackbam.at/2019/07/08/laravel-in-five-minutes-a-super-short-crash-course-for-the-awesome-php-framework-principles-and-core-functionalities/" data-a2a-title="Laravel in five minutes: A super short crash course for the awesome PHP framework (principles and core functionalities)"><img src="https://static.addtoany.com/buttons/share_save_120_16.png" alt="Share"></a></p>]]></content:encoded>
					
					<wfw:commentRss>https://blog.blackbam.at/2019/07/08/laravel-in-five-minutes-a-super-short-crash-course-for-the-awesome-php-framework-principles-and-core-functionalities/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>PostgreSQL, PL/pgSQL and Java: Quick syntactic overview with examples</title>
		<link>https://blog.blackbam.at/2013/07/03/postgresql-plpgsql-and-java-quick-syntactic-overview-with-examples/</link>
					<comments>https://blog.blackbam.at/2013/07/03/postgresql-plpgsql-and-java-quick-syntactic-overview-with-examples/#respond</comments>
		
		<dc:creator><![CDATA[Blackbam]]></dc:creator>
		<pubDate>Tue, 02 Jul 2013 22:21:11 +0000</pubDate>
				<category><![CDATA[SQL]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[JDBC]]></category>
		<category><![CDATA[plpgsql]]></category>
		<category><![CDATA[Postgresql]]></category>
		<category><![CDATA[Tutorial]]></category>
		<guid isPermaLink="false">https://blog.blackbam.at/?p=2132</guid>

					<description><![CDATA[This article on PostgreSQL is dedicated to my university course about database system, which I had to absolve this year. This post maybe useful as a quick syntactic introduction to PostgreSQL. It contains some useful examples and structures. This is not a complete tutorial. For really learning PostgreSQL you should consider reading the official documentation. [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><p>This article on PostgreSQL is dedicated to my university course about database system, which I had to absolve this year. This post maybe useful as a quick syntactic introduction to PostgreSQL. It contains some useful examples and structures. This is not a complete tutorial. For really learning<br /> PostgreSQL you should consider reading the <a href="http://www.postgresql.org/docs/">official documentation</a>.</p>
<p>&nbsp;</p>
<h2>1. Data definition and manipulation</h2>
<p>This part of the tutorial will show you the syntax of creating, changing and deleting tables in PostgreSQL. It will also show you how<br /> to insert, change and delete data in tables.</p>
<h3>1.1 Creating Sequences</h3>
<p>A sequence is an incrementing or decrementing row of numbers, which may be used to create specially structed primary keys<br /> but also just any other number sequence you may want to use when inserting data. To use a sequence you have created<br /> you usually use the the following function inside of an insert statement: nextval(&#8216;sequence_name&#8217;).</p>
<pre lang="sql">
 
 -- Creates a sequence like this: 10,20,30, ...
CREATE SEQUENCE seq_mannschaft INCREMENT BY 10 MINVALUE 10 NO MAXVALUE START WITH 10 NO CYCLE;
-- Increment by: Size of the steps
-- Minvalue: Starting value of the sequence
-- Maxvalue: Maximum value of the sequence
-- Cycle: Sequence will start with MINVALUE again when MAXVALUE is reached

-- Creates a simple sequence: 1,2,3 ... 
CREATE SEQUENCE seq_employee; 
</pre>
<h3>1.2 Creating Tables (DDL)</h3>
<pre lang="sql">
 
-- Most important types
CREATE TABLE Car (
	id SERIAL PRIMARY KEY, -- good way to create a primary key is serial
	petrol_consumption INTEGER, -- a normal integer
	model VARCHAR(128), -- varying characters (maximum length)
	cost NUMERIC(7,2), -- a numeric type
	has_golden_doors BOOLEAN, -- boolean type
	bought_at DATE, -- saves date Year, Month, Day: See date functions
	buytime TIMESTAMP -- saves time in microseconds: See date functions
);

-- Create a subtype
create table Elite_Car (
   id INTEGER PRIMARY KEY REFERENCES Car(id), -- creates a subtype
   num_of_speicals INTEGER NOT NULL
);
	
-- Most important constraints
create table Employee (
   id INTEGER PRIMARY KEY DEFAULT nextval('seq_employee'), -- use a defined sequence
   earns NUMERIC(7,2) CHECK (gehalt >= 0), -- income must be positive
   room_number INTEGER CHECK (stockwerk BETWEEN 1 AND 500), -- check range for numbers
   name NOT NULL, -- every employee must have a name
   department INTEGER -- foreign key deferred
);

CREATE TABLE Department (
	id SERIAL PRIMARY KEY,
	name VARCHAR(128),
	boss INTEGER
);

-- Adding constraints afterwards, especially: Cyclic Constraints
ALTER TABLE Employee ADD CONSTRAINT fk_department 
	FOREIGN KEY (department) REFERENCES Department(id) DEFERRABLE INITIALLY DEFERRED;
	
ALTER TABLE Department ADD CONSTRAINT fk_boss
	FOREIGN KEY (boss) REFERENCES Employee(id) DEFERRABLE INITIALLY DEFERRED;
	
CREATE TABLE In_Conflict(
	employee1 INTEGER REFERENCES Employee(id),
	employee2 INTEGER REFERENCES Employee(id),
	PRIMARY KEY (employee1,employee2) -- create primary key from multiple foreign keys
);

</pre>
<h3>1.3 Inserting Data (DML)</h3>
<pre lang="sql">-- To guarantee that a whole transaction will be done or completly canceled: Begin, Commit
BEGIN;

INSERT INTO Car(petrol_consumption,model,cost,has_golden_doors,bought_at,buytime) VALUES (6,'Audi',20000.00,false,'2012-02-19','2012-02-19 14:48');
INSERT INTO Car(petrol_consumption,model,cost,has_golden_doors,bought_at,buytime) VALUES (7,'Opel',10000.00,true,'2011-02-19','2012-02-19 14:48');

COMMIT;
</pre>
<h3>1.4 Updating data (DML)</h3>
<pre lang="sql">
 
UPDATE Car SET petrol_consumption = 12 WHERE model = 'Audi'; -- Update Data
</pre>
<h3>1.5 Deleting data (DML)</h3>
<pre lang="sql">
 
DELETE FROM Car; -- deletes everything in car
DELETE FROM Car WHERE model='Audi' AND has_golden_doors=true; -- will not delete anything
</pre>
<h3>1.6 Removing Tables, Sequences, Constraints (DDL)</h3>
<pre lang="sql">
 
DROP TABLE In_Conflict;
ALTER TABLE Department DROP CONSTRAINT fk_boss;
DROP TABLE Employee;
DROP TABLE Department;
DROP TABLE Elite_Car;
DROP TABLE Car CASCADE; -- Cascade (makes no sense here) will delete everything else which must be deleted, before this table should be deleted (so use with care)
</pre>
<h2>2. Querying data and complex queries</h2>
<p>This part of the tutorial will be an introduction to complex queries in PostgreSQL. It will show the syntax and some examples.</p>
<h3>2.1 Built in Functions and Query Structure</h3>
<p>Built in functions like these inside of queries can be used to perform simple mathematical operations, convert strings to dates, and more&#8230;</p>
<pre lang="sql">
 
|| -- string concetination
round(),sqrt() -- mathematical
to_char(),to_number() -- conversion function
to_date(), CURRENT_DATE -- date functions, CURRENT_DATE is a "constant" which will show the current date
to_char(date,'MONTH DD,YYYY'); -- date to char
EXTRACT(YEAR FROM My_Time) AS My_Year --- the EXTRACT keyword is used for getting parts of a timestamp for example
</pre>
<h3>2.2 Recursive Queries</h3>
<p>Recursive queries, quite a new feature of PostgreSQL, make it possible for a query to refer to its own output tables. The following<br /> examples will demonstrate how it works.</p>
<p>This example was found at <a href="http://jakub.fedyczak.net/post/42/">http://jakub.fedyczak.net/post/42/</a> , and I think it is a good demonstration of how recursive queries works.</p>
<pre lang="sql">
 
-- create a table
BEGIN;
create table empl (
    name text primary key,
    boss text default null
);

-- insert data
insert into empl values ('Paul',null);
insert into empl values ('Luke','Paul');
insert into empl values ('Kate','Paul');
insert into empl values ('Marge','Kate');
insert into empl values ('Edith','Kate');
insert into empl values ('Pam','Kate');
insert into empl values ('Carol','Luke');
insert into empl values ('John','Luke');
insert into empl values ('Jack','Carol');
insert into empl values ('Alex','Carol');
COMMIT;

-- do a recursive query, to determine the "boss path" for each employee
WITH RECURSIVE t(level,path,boss,name) as (
        select 0,name,boss,name from empl where boss is null
    union all
        select
            level + 1,
            path || ' > ' || empl.name,
            empl.boss,
            empl.name 
        from 
            empl join t 
                on empl.boss = t.name
) select * from t order by path;

-- result
/*
 level |            path            | boss  | name
-------+----------------------------+-------+-------
     0 | Paul                       |       | Paul
     1 | Paul > Kate                | Paul  | Kate
     2 | Paul > Kate > Edith        | Kate  | Edith
     2 | Paul > Kate > Marge        | Kate  | Marge
     2 | Paul > Kate > Pam          | Kate  | Pam
     1 | Paul > Luke                | Paul  | Luke
     2 | Paul > Luke > Carol        | Luke  | Carol
     3 | Paul > Luke > Carol > Alex | Carol | Alex
     3 | Paul > Luke > Carol > Jack | Carol | Jack
     2 | Paul > Luke > John         | Luke  | John
(10 lines)
*/
</pre>
<p>This is another example on recursive queries, which is intended to show how it works.</p>
<pre lang="sql">/* Table:

 follower | follows
----------+---------
 a        | b
 a        | c
 a        | e
 b        | a
 b        | c
 b        | d
 b        | e
 c        | e
 d        | b
 d        | e
(10 lines)

*/

-- recursive query
WITH RECURSIVE temp(a,b) AS (
	SELECT * FROM follows
UNION ALL
	SELECT f1.follower, f2.follows
	FROM follows f1, follows f2
	WHERE f1.follows = f2.follower
)
SELECT * FROM temp;

-- result
/*
a | b
--+---
a | b
a | c
a | e
b | a
b | c
b | d
b | e
c | e
d | b
d | e
b | b
b | c
b | e
a | a
a | c
a | d
a | e
d | a
d | c
d | d
d | e
a | e
b | e
b | b
b | e

*/

-- recursive query with group / count
SELECT a, count(*) FROM temp
GROUP BY a ORDER BY a;

&acute;/*
 a | count
---+-------
 a |     8
 b |    10
 c |     1
 d |     6
(4 Zeilen)
*/
</pre>
<h3>2.3 Views</h3>
<p>A view appears as a table, but in fact it is just the result of a query on one or many other tables.</p>
<pre lang="sql">
 
-- Create a simple table and insert data
CREATE TABLE data(a int4, b int4);

INSERT INTO data VALUES(12, 23);
INSERT INTO data VALUES(3, 7);
 
 -- create a view on this table
CREATE VIEW view_data 
	AS SELECT a*2 AS c, b*2 AS d 
	FROM data;
	
/*

Result: SELECT * FROM view_data;

 c | d
----+----
 24 | 46
 6  | 14
(2 rows)

*/
</pre>
<h3>2.4 Some little things to remember</h3>
<pre lang="sql">
 
-- normal WITH: for creating intermediate results (tables/relations) which may be used in a complex query
WITH audis AS (
	SELECT id,model FROM cars WHERE brand='Audi'
) SELECT DISTINCT model FROM audi;

-- connecting results with union:
UNION --> duplicates are eliminated
UNION ALL --> duplicates are not eliminated

-- Comparing multiple results with a single value. Example:
where Semester >= all ( select Semester from Studenten );
-- same as 
where Semester = ( select max( Semester ) from Studenten );


-- GROUP BY ... HAVING Example with COUNT
-- How many books are stored in the database for each publisher?
SELECT COUNT(e.isbn) AS "number of books",
       p.name AS publisher
       FROM editions AS e 
	   INNER JOIN publishers AS p
            ON (e.publisher_id = p.id)
			GROUP BY p.name;

-- GROUP BY ... HAVING Example with SUM		
-- How many pages does each publisher have in all his books together?
SELECT SUM(e.num_of_pages) AS "number of pages",
       p.name AS publisher
       FROM editions AS e 
	   INNER JOIN publishers AS p
            ON (e.publisher_id = p.id)
			GROUP BY p.name;
</pre>
<h3>2.5 Existential quantifier / Universal quantifier</h3>
<p>There is an existential quantifier in PostgreSQL:</p>
<pre lang="sql">-- Existential quantifier (check if resulting table is empty)
NOT EXISTS
</pre>
<p>There is no universal quantifier in SQL, so this must be simulated. Just see the following example:</p>
<p>&#8220;Which students attended all lectures which last 4 hours?&#8221; is the same as<br /> &#8220;Search all Students for which is not true: There is a 4 hour lecture, which this student did not hear&#8221;.</p>
<pre lang="sql">
 
select s.*
from Students s
where not exists
	(select *
	from Lectures l
	where l.SWS = 4 and
	s.MatrNr not in ( select a.MatrNr
		from attend a
		where a.VorlNr = l.VorlNr ));
</pre>
<h3>2.2 Some complex query examples (german)</h3>
<pre lang="sql">/* Geben Sie ID, Rufname sowie die ID und den Nachnamen des Leiters jener Mannschaften aus, die bereits mit allen Bergefahrzeugen bei Eins&auml;tzen waren. */

SELECT ID, Rufname, Leiter, (SELECT Nachname FROM Person WHERE ID = Leiter) LeiterName
    FROM Mannschaft WHERE NOT EXISTS
        (SELECT * FROM Bergefahrzeug WHERE NOT EXISTS 
            (SELECT * FROM Einsatz WHERE Einsatz.mannschaft = Mannschaft.ID AND Einsatz.fahrzeug = Bergefahrzeug.ID));



/*
W&auml;hlen Sie per Hand einen Dienstgrad aus, der anderen Dienstgraden untergeordnet ist. Schreiben Sie eine Anfrage, die diesen Dienstgrad ausgibt, sowie rekursiv alle &uuml;bergeordneten Dienstgrade. Geben Sie f&uuml;r jeden Dienstgrad die ID, Beschreibung sowie das zugeh&ouml;rige Gehalt und den Gehaltsunterschied zum n&auml;chstniedrigen Dienstgrad aus. Sollte es keinen niedrigeren Dienstgrad geben, soll der Inhalt der Spalte 0 sein. Passen Sie die Tupel in Ihrer Datenbank so an, dass es zu der von Ihnen ausgew&auml;hlten Kategorie mindestens zwei Ebenen &uuml;bergeordneter Kategorien gibt. Achten Sie darauf, dass Ihre Daten keine Schleife enthalten, da ansonsten die Abfrage fehlschl&auml;gt.
*/

WITH RECURSIVE Hierarchie (ID, Bezeichnung, Vorgesetzter, Gehalt, Unterschied) AS (
	SELECT ID, Bezeichnung, Vorgesetzter, Gehalt, CAST(0.0 AS NUMERIC) FROM Dienstgrad WHERE ID = 8
	UNION ALL
	SELECT Dienstgrad.ID, 
           Dienstgrad.Bezeichnung, Dienstgrad.Vorgesetzter, 
           Dienstgrad.Gehalt, Dienstgrad.Gehalt - Hierarchie.Gehalt
	    FROM Hierarchie JOIN Dienstgrad ON (Hierarchie.Vorgesetzter = Dienstgrad.ID)
)
SELECT ID, Bezeichnung, Gehalt, Unterschied FROM Hierarchie;



/*
Geben Sie die ID, Vor- und Nachname sowie Anzahl der Berichte der Personen aus, die an nicht mehr als drei Eins&auml;tzen teilgenommen haben und gleichzeitig die wenigsten Berichte verfasst haben. Vergessen Sie nicht darauf, dass im Falle, dass noch keine Berichte erstellt wurden auch die Personen ausgegeben werden, die keine Berichte verfasst haben.
*/

SELECT Person.ID, Vorname, Nachname, COUNT(bericht.id) FROM Person LEFT JOIN Bericht ON Bericht.Verfasser = Person.ID 
    WHERE Person.ID IN (SELECT Person.ID FROM Person JOIN Einsatz ON Einsatz.Mannschaft = Person.Mannschaft 
        GROUP BY Person.ID HAVING COUNT(*) <= 3) GROUP BY Person.ID, Vorname, Nachname 
    HAVING COUNT(*) <= ALL
        (SELECT COUNT(*) FROM Person LEFT JOIN Bericht ON Bericht.Verfasser = Person.ID 
            WHERE Person.ID IN (SELECT Person.ID FROM Person JOIN Einsatz ON Einsatz.Mannschaft = Person.Mannschaft 
                GROUP BY Person.ID HAVING COUNT(*) <= 3) GROUP BY Person.ID, Vorname, Nachname);

</pre>
<h2>3. Functions / Procedures and Triggers</h2>
<p>This part of the article is about PL/pgSQL (Procedural Language/PostgreSQL) which is one possibility to extend some PostgreSQL database with advanced<br /> functions and procedures, beyond the possibilities of standard SQL. PL/pgSQL is just one of many possibilities for this purpose.</p>
<h3>3.1 Important constructs</h3>
<pre lang="sql">
 
-- creating query loops
FOR variable IN statement
LOOP
	-- each row can be accessed here
END LOOP;

-- an alternative to query loops
CURSOR, RECORD, REFCURSOR, Copying types;
</pre>
<h3>3.2 Function Example</h3>
<p>This is an example of a function in PL/pgSQL.</p>
<pre lang="sql">
 
CREATE OR REPLACE FUNCTION p_erhoehe_dienstgrad(jahre INTEGER) RETURNS VOID AS $$
DECLARE
	sw_person Person%ROWTYPE;
	old_dienstgrad Dienstgrad%ROWTYPE;
	new_dienstgrad Dienstgrad%ROWTYPE;
BEGIN
	IF jahre < 1 THEN
		RAISE EXCEPTION 'Mindestens 1 Jahr f&uuml;r den Aufstieg n&ouml;tig.';
	END IF;
	
	FOR sw_person IN SELECT * FROM Person p
	LOOP
		SELECT * FROM Dienstgrad d INTO old_dienstgrad WHERE sw_person.dienstgrad = d.id;
		
		IF extract(year from age(sw_person.dienstgrad_seit)) > = jahre THEN

			IF old_dienstgrad.vorgesetzter IS NOT NULL THEN
				SELECT * FROM Dienstgrad INTO new_dienstgrad WHERE Dienstgrad.id = old_dienstgrad.vorgesetzter;
				UPDATE Person SET dienstgrad = new_dienstgrad.id, dienstgrad_seit = CURRENT_DATE WHERE Person.id = sw_person.id;
				RAISE NOTICE 'Die Person % % wurde bef&ouml;rdert vom % zum %.',sw_person.vorname, sw_person.nachname,old_dienstgrad.bezeichnung,new_dienstgrad.bezeichnung;
			ELSE
				RAISE NOTICE 'Die Person % % befindet sich bereits im h&ouml;chsten Dienstgrad % und ist daher nicht aufgestiegen.',sw_person.vorname,sw_person.nachname,old_dienstgrad.bezeichnung;
			END IF;
		ELSE
			RAISE NOTICE 'Die Person % % befindet sich nach wie vor im Dienstgrad %',sw_person.vorname,sw_person.nachname,old_dienstgrad.bezeichnung;
		END IF;
	END LOOP;
END
$$ LANGUAGE plpgsql;

</pre>
<h3>3.3 Trigger Example</h3>
<p>This is an example of a trigger in PostgreSQL. A trigger is a special function which can be "triggered" before / after inserting, updating or deleting data,<br /> which can be used to control certain flows.</p>
<pre lang="sql">
 
CREATE OR REPLACE FUNCTION check_einsatz_allowed() RETURNS TRIGGER AS $$
	DECLARE
		
	BEGIN
		IF NOT EXISTS (SELECT * FROM Einsatz e WHERE e.mannschaft = NEW.mannschaft AND e.ereignis = NEW.ereignis) THEN
			IF NOT EXISTS (SELECT * FROM Einsatz e WHERE e.ereignis = NEW.ereignis AND e.fahrzeug = NEW.fahrzeug) THEN
				RETURN NEW;
			END IF;
			RAISE EXCEPTION 'Dieses Fahrzeug ist f&uuml;r diesen Einsatz bereits reserviert';
		END IF;
		RAISE EXCEPTION 'Diese Mannschaft f&auml;hrt bereits mit einem Fahrzeug zu dem gew&auml;hlten Ereignis';
	END
$$ LANGUAGE plpgsql;

CREATE TRIGGER chk_einsatz
BEFORE INSERT ON Einsatz
FOR EACH ROW EXECUTE PROCEDURE check_einsatz_allowed();

</pre>
<h2>4. JDBC</h2>
<p>This part is about using PostgreSQL in combination with Java (JDBC driver). The following examples demonstrate how it basically works.</p>
<p>Zusammenfassung PostgreSQL</p>
<p>&nbsp;</p>
<ol>
<li>Register driver</li>
<li>Create connection (DriverManger.getConnection)</li>
<li>Create a statement (f.e. Statement, PreparedStatement, CallableStatement)</li>
<li>Give a SQL statement to a query or prepare with prepareStatement / prepareCall</li>
<li>If using a preparedStatement / callableStatement: statement.setString(pos,value), Example: statement.setInt(1,1)</li>
<li>ResultSet = Statement.executeQuery / executeUpdate</li>
<li>Loop through results: (while (ResultSet.next()))</li>
<li>Get a result inside this loop: ResultSet.getInt() / ResultSet.getString()</li>
<li>Close all connections</li>
</ol>
<pre lang="java">
 
try {
	Class.forName("org.postgresql.Driver");
} catch (ClassNotFoundException e) {
	// TODO Auto-generated catch block
	e.printStackTrace();
}

System.out.println("Found");

try {
	Connection c = DriverManager.getConnection("jdbc:postgresql://localhost/exp","dave","hallo123");
	
	
	//////////// Normal statements
	// advanced options: c.createStatement(ResultSet.CONCUR_UPDATABLE, ResultSet.TYPE_SCROLL_INSENSITIVE
	Statement stmt = c.createStatement();
	
	ResultSet rs = stmt.executeQuery("SELECT * FROM empl"); // could also be: executeUpdate()
	
	// Navigation: first(), last(), next(), previous(), beforeFirst(), beforeLast(), absolute(x), relative(x)
	while(rs.next()) {
		// other Methods: getString(), getFloat(), getDouble(), getDate(), getTimestamp()
		System.out.println("Name: "+rs.getString(1)+" Boss: "+rs.getString(2));
		
		// update: rs.updateFloat("Note",l_Note-1); rs.updateRow();
		// deletes: rs.deleteRow();
	}
	
	
	/////////// Prepared Statements
	PreparedStatement pstmt = c.prepareStatement("SELECT underbosses.name FROM empl as underbosses WHERE boss = ? ");
	
	pstmt.setString(1, "Paul");
	rs = pstmt.executeQuery();
	
	while(rs.next()) {
		System.out.println("Underboss: "+rs.getString(1));
	}
	
	
	/////////// Callable Statements
	CallableStatement cs = c.prepareCall("{call getBastards(?,?}");
	cs.setInt(1,4);
	cs.setString(2, "special");
	cs.registerOutParameter(2,Types.INTEGER);
	
	cs.executeQuery(); 
	int bastards = cs.getInt(2);
	
	rs.close();
	cs.close();
	stmt.close();
	pstmt.close();
	c.close();
	
} catch (SQLException e) {
	// TODO Auto-generated catch block
	e.printStackTrace();
}
</pre>
<p>&nbsp;</p></p>
<p><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fblog.blackbam.at%2F2013%2F07%2F03%2Fpostgresql-plpgsql-and-java-quick-syntactic-overview-with-examples%2F&#038;title=PostgreSQL%2C%20PL%2FpgSQL%20and%20Java%3A%20Quick%20syntactic%20overview%20with%20examples" data-a2a-url="https://blog.blackbam.at/2013/07/03/postgresql-plpgsql-and-java-quick-syntactic-overview-with-examples/" data-a2a-title="PostgreSQL, PL/pgSQL and Java: Quick syntactic overview with examples"><img src="https://static.addtoany.com/buttons/share_save_120_16.png" alt="Share"></a></p>]]></content:encoded>
					
					<wfw:commentRss>https://blog.blackbam.at/2013/07/03/postgresql-plpgsql-and-java-quick-syntactic-overview-with-examples/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Java RMI five Minutes tutorial</title>
		<link>https://blog.blackbam.at/2013/01/23/java-rmi-5-minutes-tutorial/</link>
					<comments>https://blog.blackbam.at/2013/01/23/java-rmi-5-minutes-tutorial/#respond</comments>
		
		<dc:creator><![CDATA[Blackbam]]></dc:creator>
		<pubDate>Wed, 23 Jan 2013 08:38:47 +0000</pubDate>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[networking]]></category>
		<category><![CDATA[remote]]></category>
		<category><![CDATA[rmi]]></category>
		<category><![CDATA[Tutorial]]></category>
		<guid isPermaLink="false">https://blog.blackbam.at/?p=2030</guid>

					<description><![CDATA[This ultra short tutorial is just a summary of how Java RMI (remote method invocation) works. For explanation please check one of the other tutorials which you will find easily easily your favorite search engine. 1. Write RMI-Server Interface extends package java.rmi.Remote provide all methods to be called remotely each methods must through a remote [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>This ultra short tutorial is just a summary of how Java RMI (remote method invocation) works. For explanation please check one of the other tutorials which you will find easily easily your favorite search engine.</p>
<h2>1. Write RMI-Server Interface</h2>
<ul>
<li>extends package java.rmi.Remote</li>
<li>provide all methods to be called remotely</li>
<li>each methods must through a remote exception</li>
</ul>
<pre lang="java">
import java.rmi.*;
 
public interface ServerInterface extends Remote {
     public void method1() throws RemoteException;
     public int method2() throws RemoteException;
     // ...
}</pre>
<h2>2. Write Server Class</h2>
<ul>
<li>implements RMI-Server Interface</li>
<li>extends UnicastRemoteObject (at least for simple RMI)</li>
<li>Constructor throws java.rmi.RemoteException</li>
<li>must be registered at local registry</li>
</ul>
<p>&nbsp;</p>
<pre lang="java"> 
import java.rmi.*;
import java.net.MalformedURLExcpetion;
import java.rmi.registry.*;
import java.rmi.server.UnicastRemoteObject;
 
public class MyServer extends UnicastRemoteObject implements ServerInterface {
 
  MyServer() throws RemoteException {
    super();
  }
 
  public static void main(String[] args) {

    try {
      LocateRegistry.createRegistry(Registry.REGISTRY_PORT);
    } catch (RemoteException ex) {
      System.out.println(ex.getMessage());
    }
    try {
      Naming.rebind("MyServer", new MyServer());
    } catch (MalformedURLException ex) {
      System.out.println(ex.getMessage());
    }
    catch (RemoteException ex) {
      System.out.println(ex.getMessage());
    }
  }
  // ...
}</pre>
<h2>3. Write a client</h2>
<ul>
<li>get remote reference</li>
<li>call remote methods</li>
<li>be careful with rmi-specific problems (a more detailed tutorial will explain to you)</li>
</ul>
<p>&nbsp;</p>
<pre lang="java">// any class, ...
// url expects String in url format (e.g. http://127.0.0.1/MyServer for local testing)
 
try {
      ServerInterface server = (ServerInterface) Naming.lookup(url);
      server.method1();
      int calculated_by_server = server.method2();
      // ...
} catch (Exception ex) {

}</pre>
<p>&nbsp;</p>
<p><strong>API reference:</strong></p>
<ul>
<li>RMI: <a href="http://java.sun.com/javase/6/docs/api/index.html?java/rmi/Remote.html" rel="nofollow">Remote API</a>, <a href="http://java.sun.com/javase/6/docs/api/index.html?java/rmi/server/UnicastRemoteObject.html" rel="nofollow">UnicastRemoteObject API</a>, <a href="http://java.sun.com/javase/6/docs/api/index.html?java/rmi/registry/Registry.html" rel="nofollow">Registry API</a>, <a href="http://java.sun.com/javase/6/docs/api/index.html?java/rmi/registry/LocateRegistry.html" rel="nofollow">LocateRegistry API</a></li>
<li>Properties: <a href="http://java.sun.com/javase/6/docs/api/index.html?java/util/Properties.html" rel="nofollow">Properties API</a></li>
<li>IO: <a href="http://java.sun.com/javase/6/docs/api/index.html?java/io/package-summary.html" rel="nofollow">IO Package API</a></li>
</ul>
<p>&nbsp;</p>
<p><strong>Further reading:</strong><br />
<a href="http://docs.oracle.com/javase/tutorial/rmi/index.html">http://docs.oracle.com/javase/tutorial/rmi/index.html</a></p>
<p><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fblog.blackbam.at%2F2013%2F01%2F23%2Fjava-rmi-5-minutes-tutorial%2F&#038;title=Java%20RMI%20five%20Minutes%20tutorial" data-a2a-url="https://blog.blackbam.at/2013/01/23/java-rmi-5-minutes-tutorial/" data-a2a-title="Java RMI five Minutes tutorial"><img src="https://static.addtoany.com/buttons/share_save_120_16.png" alt="Share"></a></p>]]></content:encoded>
					
					<wfw:commentRss>https://blog.blackbam.at/2013/01/23/java-rmi-5-minutes-tutorial/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Implementing a simple and flexible paging algorithm using PHP</title>
		<link>https://blog.blackbam.at/2011/07/18/implementing-a-simple-and-flexible-paging-algorithm-using-php/</link>
					<comments>https://blog.blackbam.at/2011/07/18/implementing-a-simple-and-flexible-paging-algorithm-using-php/#respond</comments>
		
		<dc:creator><![CDATA[Blackbam]]></dc:creator>
		<pubDate>Mon, 18 Jul 2011 08:00:47 +0000</pubDate>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[algorithm]]></category>
		<category><![CDATA[paging]]></category>
		<category><![CDATA[Tutorial]]></category>
		<guid isPermaLink="false">https://blog.blackbam.at/?p=1403</guid>

					<description><![CDATA[A very common problem in programming web pages is to implement paging. Paging is required whenever there is an undefined amount of items (usually queried from a database) with a maximum amount of items to be displayed on one page. If there is more than one page, there must be a possibility to navigate through [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>A very common problem in programming web pages is to implement paging. Paging is required whenever there is an undefined amount of items (usually queried from a database) with a maximum amount of items to be displayed on one page. If there is more than one page, there must be a possibility to navigate through these pages while each page displays the desired amount of items.</p>
<h2>Case example</h2>
<p>Imagine you have a blog with a dynamic number of articles, while the current number of articles is 37. You want to create an article overview yourself, with the following conditions:<br />
1. The maximum number of articles on an overview page is 10<br />
2. A navigation to navigate to the next and previous 10 articles is required<br />
The result will be, that you need to have four pages:<br />
page 1: article 1-10,<br />
page 2: article 11-20,<br />
page 3: article 21-30,<br />
page 4: article 30-37<br />
<br />
Knowing the result, it is easy to develop a navigation between these pages: You just need to know the number of articles to show on each page (usually decided when coding the script), the page you are currently on (usually passed via Post- or Get- paramters and the number of all results you have to display (usually from counting the SQL results). <br />
But how can this result always be calculated dynamically?</p>
<h2>The script</h2>
<p>The following script shows the basic implementation of the page results algorithm in PHP:</p>
<pre lang="php">
/*** The three paramters ***/
// Make a query to get all your results (like posts, images, whatever)
$resultsOverall = 0;
 
// Results per page (the number of results per page to be shown)
$resultsPerPage = 10;
 
// Page number (the current page number, usually $_REQUEST['pageNumber'] or something similar)
$pageNumber = 1; 
 
if(isset($_REQUEST["pageNumber"]) && $_REQUEST["pageNumber"] > 1) {
	$pageNumber = $_REQUEST["pageNumber"];
}
 
 
/**** The logic ****/
// determine the first result to show
$resultsFrom = ($pageNumber*$resultsPerPage-$resultsPerPage+1);
 
// determine the last result to show
$resultsTo = ($resultsFrom-1)+$resultsPerPage;
 
if($resultsTo > $resultsOverall) {
	$resultsTo = $resultsOverall;
}
 
// determine number of Pages (for example to show in a navigation)
$allPages = ceil($resultsOverall / $resultsPerPage);
</pre>
<p><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fblog.blackbam.at%2F2011%2F07%2F18%2Fimplementing-a-simple-and-flexible-paging-algorithm-using-php%2F&#038;title=Implementing%20a%20simple%20and%20flexible%20paging%20algorithm%20using%20PHP" data-a2a-url="https://blog.blackbam.at/2011/07/18/implementing-a-simple-and-flexible-paging-algorithm-using-php/" data-a2a-title="Implementing a simple and flexible paging algorithm using PHP"><img src="https://static.addtoany.com/buttons/share_save_120_16.png" alt="Share"></a></p>]]></content:encoded>
					
					<wfw:commentRss>https://blog.blackbam.at/2011/07/18/implementing-a-simple-and-flexible-paging-algorithm-using-php/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Some useful tipps for CSS development</title>
		<link>https://blog.blackbam.at/2010/12/16/some-tipps-for-better-css/</link>
					<comments>https://blog.blackbam.at/2010/12/16/some-tipps-for-better-css/#respond</comments>
		
		<dc:creator><![CDATA[Blackbam]]></dc:creator>
		<pubDate>Wed, 15 Dec 2010 23:58:16 +0000</pubDate>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[CSS Sprites]]></category>
		<category><![CDATA[CSS tipps]]></category>
		<category><![CDATA[font-face]]></category>
		<category><![CDATA[LessCSS]]></category>
		<category><![CDATA[Tutorial]]></category>
		<guid isPermaLink="false">http://www.blackbam.at/blog/?p=1008</guid>

					<description><![CDATA[Recently I was confronted with some lectures about certain topics relating to Cascading Stylesheets. I decided to write a short summary to remember and use these things as I need them in future projects. 1. CSS-Sprites CSS-Sprites are the idea of using one large as background for multiple graphics on a web page. Relative positioning [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><br class="spacer_" /></p>
<p>Recently I was confronted with some lectures about certain topics relating to Cascading Stylesheets. I decided to write a short summary to remember and use these things as I need them in future projects.</p>
<p><br class="spacer_" /></p>
<h2>1. CSS-Sprites</h2>
<p>CSS-Sprites are the idea of using one large as background for multiple graphics on a web page. Relative positioning of the background always guarantees that the correct part of the &#8220;master image&#8221; is displayed.</p>
<p><br class="spacer_" /></p>
<h4>Example of Sprites</h4>
<p>(only the correct button is displayed on the page).</p>
<p><br class="spacer_" /></p>
<p><img decoding="async" src="file:///C:/Users/Blackbam/AppData/Local/Temp/moz-screenshot-2.png" alt="" /></p>
<p><a rel="attachment wp-att-1013" href="https://blog.blackbam.at/2010/12/16/some-tipps-for-better-css/sprites/"><img decoding="async" class="alignnone size-full wp-image-1013" title="CSS-Sprites" src="https://blog.blackbam.at/wp-content/uploads/2010/12/sprites.png" alt="" width="160" height="121" /></a></p>
<p><br class="spacer_" /></p>
<h4>Why use CSS-sprites?</h4>
<ul>
<li>the performance of a site with high traffic is much better</li>
<li>there is only one HTTP-Request required, instead of many (also a performance thing)</li>
<li>changing the design can be much faster, if there is only one image (imagine you have to build a lot of child theme sites)</li>
</ul>
<p><br class="spacer_" /></p>
<h4>Disadvantages</h4>
<ul>
<li>can become complex if over-used or with big webpages</li>
<li>problems with dynamic layouts, if there are changes on the site (be careful)</li>
</ul>
<p><br class="spacer_" /></p>
<h4>Implementation</h4>
<pre lang="CSS">background-position: 123px 123px;

</pre>
<h4>Further instructions and examples</h4>
<p><a href="http://www.css-tricks.com/date-display-with-sprites/">http://www.css-tricks.com/date-display-with-sprites/</a></p>
<p><br class="spacer_" /></p>
<p><br class="spacer_" /></p>
<h2>2. Less CSS</h2>
<p>Less CSS is a project to use variables, mixins, nested options and nested rules with CSS (Why is this not possible with native CSS?) It is an interresting way to simplify and speed up CSS development.</p>
<p><br class="spacer_" /></p>
<p><strong>Example</strong></p>
<p><br class="spacer_" /></p>
<pre lang="CSS">/* variables */
@brand_color: #4D926F;

#header {
  color: @brand_color;
}

h2 {
  color: @brand_color;
}

/* mixins */
.rounded_corners (@radius: 5px) {
  -moz-border-radius: @radius;
  -webkit-border-radius: @radius;
  border-radius: @radius;
}

#header {
  .rounded_corners;
}

#footer {
  .rounded_corners(10px);
}

/* nested rules */
#header {
  color: red;
  a {
    font-weight: bold;
    text-decoration: none;
  }
}

/* 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;
}
</pre>
<p><br class="spacer_" /></p>
<h4>Why use CSS-sprites?</h4>
<p>Because they faster and cleaner CSS development is possible, with even more possibilities. The CSS must be interpreted by Javascript or PHP before it is usable by a browser &#8211; of course this is a performance desaster &#8211; but you can use one-time interpreted CSS for your project in the end, so there is no need to do this on a running website!</p>
<p><br class="spacer_" /></p>
<p><br class="spacer_" /></p>
<h4>Implementation and further instructions</h4>
<p><a href="http://lesscss.org/">http://lesscss.org/</a></p>
<p><br class="spacer_" /></p>
<p><br class="spacer_" /></p>
<p>Recently I was confronted with some lectures about certain topics  relating to Cascading Stylesheets. I decided to write a short summary to  remember and use these things as I need them in future projects.</p>
<p><br class="spacer_" /></p>
<p><br class="spacer_" /></p>
<h2>3. Use Cross-Browser @font-face</h2>
<p>@font-face is an very old CSS property, which makes it possible, to use any font on a website, which you want to (as long as you have the rights to do this). This is less work to do than using images and much more interresting than only using the standard fonts.</p>
<p><br class="spacer_" /></p>
<h4>Example of @font-face</h4>
<p>You can also use exotic fonts as normal (robot readable) fonts on a website, like this:</p>
<p><br class="spacer_" /></p>
<p><a rel="attachment wp-att-1034" href="https://blog.blackbam.at/2010/12/16/some-tipps-for-better-css/font-face-exmaple-sears-tower/"><img decoding="async" class="alignnone size-medium wp-image-1034" title="font-face-exmaple-sears-tower" src="https://blog.blackbam.at/wp-content/uploads/2010/12/font-face-exmaple-sears-tower-450x77.png" alt="" width="264" height="45" srcset="https://blog.blackbam.at/wp-content/uploads/2010/12/font-face-exmaple-sears-tower-450x77.png 450w, https://blog.blackbam.at/wp-content/uploads/2010/12/font-face-exmaple-sears-tower.png 508w" sizes="(max-width: 264px) 100vw, 264px" /></a><br class="spacer_" /></p>
<p><br class="spacer_" /></p>
<p><img decoding="async" src="file:///C:/Users/Blackbam/AppData/Local/Temp/moz-screenshot-2.png" alt="" /></p>
<p><br class="spacer_" /></p>
<h4>Why use @font-face?</h4>
<ul>
<li>individual websites with artistic elements can use normal text</li>
</ul>
<p><br class="spacer_" /></p>
<h4>Disadvantages</h4>
<ul>
<li>implementation and conversion may cost some extra minutes</li>
<li>maybe legal problems with commercial fonts</li>
</ul>
<ul>
<p><br class="spacer_" /></p>
</ul>
<h4>Implementation</h4>
<p>For cross-browser implementation, you have to provide your font in at least 3 formats currently &#8211;  EOT,WOFF and TTF.</p>
<p><br class="spacer_" /></p>
<pre lang="CSS">@font-face {
  font-family: 'WebFont';
  src: url('myfont.eot');  /* IE6-8 */
  src: local('☺'),
        url('myfont.woff') format('woff'),  /* FF3.6, IE9 */
        url('myfont.ttf') format('truetype');  /* Saf3+,Chrome,FF3.5,Opera10+ */
}

h1 {
  font-family:'WebFont',Arial,Helvetica,sans-serif;
}
</pre>
<h4>Further instructions and examples</h4>
<p><a href="http://www.font2web.com/">http://www.font2web.com/</a> (convertes a font from one font format to all expected formats)</p>
<p><a href="http://www.fontsquirrel.com/">http://www.fontsquirrel.com/</a> (a lot of FREE fonts to use with your web project)</p>
<p><a href="http://paulirish.com/2009/fighting-the-font-face-fout/">http://paulirish.com/2009/fighting-the-font-face-fout/</a> (prevent Firefox to show the wrong font, solve a lot of forther problems)</p>
<p><br class="spacer_" /></p>
<p><br class="spacer_" /></p>
<p>This might list might be continued&#8230;<br class="spacer_" /></p>
<p><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fblog.blackbam.at%2F2010%2F12%2F16%2Fsome-tipps-for-better-css%2F&#038;title=Some%20useful%20tipps%20for%20CSS%20development" data-a2a-url="https://blog.blackbam.at/2010/12/16/some-tipps-for-better-css/" data-a2a-title="Some useful tipps for CSS development"><img src="https://static.addtoany.com/buttons/share_save_120_16.png" alt="Share"></a></p>]]></content:encoded>
					
					<wfw:commentRss>https://blog.blackbam.at/2010/12/16/some-tipps-for-better-css/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
