Archivio dell'autore: alexintosh

.htaccess redirect from olddomain to newdomain

A friend of mine wanted to redirect an old domain to a new doman, he made a simple 301 redirect but as the server physical ip was the same he falled into an redirect loop between domains.

What he needed to fix that is an if condition in the rewrite rule, I made this snipplet for him.

RewriteBase /
RewriteCond %{HTTP_HOST} !newdomain.com$ [NC]
RewriteRule ^(.*)$ http://newdomain.com/$1 [L,R=301]

Webkit custom scrollbar iOs style

I wanted to reproduce the look and feel of the ios scrollbar, so I played with the
::-webkit-scrollbar property.

Check out the demo, here

Here the code:

::-webkit-scrollbar {
width: 10px;
height: 10px;
}
::-webkit-scrollbar-button:start:decrement,
::-webkit-scrollbar-button:end:increment {
height: 30px;
display: block;
background-color: transparent;
}
::-webkit-scrollbar-track-piece {
background-color: #E9E9E9;
-webkit-border-radius: 6px;
}
::-webkit-scrollbar-thumb:vertical {
height: 50px;
background-color: #999;
border: 1px solid #eee;
-webkit-border-radius: 6px;
}

Tip: Fix random zoom on ipad orientation change

If you have the width set in the viewport :

<meta name = "viewport" content = "width=device-width; initial-scale=1.0;
 maximum-scale=1.0;"
/>

And then change the orientation it will randomly zoom in sometimes (especially if you are dragging on the screen) to fix this don’t set a width here I used :

<meta id="viewport" name="viewport" content="initial-scale=1.0; user-scalable=0;
minimum-scale=1.0; maximum-scale=1.0"
/>

This fixes the zoom whatever happens then you can use either window.onorientationchange event or if you want it to be platform independant (handy for testing) the window.innerWidth method.

Tip: Use Code igniter methods without instance a class

Sometimes making a class in Code Igniter you could need to use some method of Code igniter (database class for examples) without instance the class itself, for example in static method.

In this case, you can use the Code Igniter instance itself:

$ci_ins =& get_instance();
$ci_ins->load->model("some model");
$ci_ins-->db->insert(); //Using database

Leggere le variabili GET in javascript

Snipplet per leggere le variabili GET in Javascript

function GET(q,s)
{
s = s ? s : window.location.search;
var re = new RegExp('&'+q+'(?:=([^&]*))?(?=&|$)','i');
return (s=s.replace(/^\?/,'&').match(re)) ? (typeof s[1] == 'undefined' ? '' : decodeURIComponent(s[1])) : undefined;
}

Esempio:

// http://test.com/index.php?v=test
var var1 = GET('v');

alert(var1);

Ho trovato questa ottima funzione qui
Credits tuttavia andava fixata la regex, per questo la posto.

Get Root – Find iframe parent location

This function is useful to determinate information about the page who host an iframe from the iframe.

function get_root(obj, current_ref) {
if(obj.parent.location.href != current_ref) {
return get_root(obj.parent, obj.location.href);
}
else {
return obj.location.href;
}
}

Usage:

get_root(window, window.location.href)

Credits to: 3xlstudio

http://snipplr.com/view/60285/ifram-get-parent/

 

 

 

Stuxnet – La prima arma fatta interamente di codice.

Stuxnet is a Microsoft Windows computer worm discovered in July 2010 that targets industrial software and equipment. While it is not the first time that crackers have targeted industrial systems,it is the first discovered malware that spies on and subverts industrial systems,and the first to include a programmable logic controller (PLC) rootkit.

E’ possibile scaricare il codice sorcente, download