Skip to content

Instantly share code, notes, and snippets.

View N-Porsh's full-sized avatar

Nikita Porshnjakov N-Porsh

  • Tallinn, Estonia
View GitHub Profile
@N-Porsh
N-Porsh / setGetCookie.js
Last active August 29, 2015 14:07
Cookies
$.setCookie = function(cname, cvalue, exdays) {
var d = new Date();
d.setTime(d.getTime() + (exdays*24*60*60*1000));
var expires = "expires="+d.toGMTString();
document.cookie = cname + "=" + cvalue + "; " + expires;
}
$.getCookie = function(cname) {
var name = cname + "=";
var ca = document.cookie.split(';');
for(var i=0; i<ca.length; i++) {
@N-Porsh
N-Porsh / tabs.js
Last active August 29, 2015 14:11
simple jquery tabs
/*
<ul class='tabs'>
<li><a href='#tab1'>most viewed</a></li>
<li><a href='#tab2'>recent</a></li>
<li><a href='#tab3'>most commented</a></li>
</ul>
<div id='tab1'>
content 1111
</div>
<div id='tab2'>
@N-Porsh
N-Porsh / gist:0d56dd4d52747d7bd86b
Last active August 29, 2015 14:22
JavaScript: localStorage - cookies replacement
// thin wrapper around local-storage to avoid
// errors if the browser does not support it.
var globalVar.localStorage = {
set: function(key, value) {
if (!swarm.localStorage.canStore()) {
return null;
}
return window.localStorage.setItem(key, value);
},
<?php
try {
$pdo = new PDO(
'mysql:host=localhost;dbname=test_database',
'username',
'password',
array(
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'
@N-Porsh
N-Porsh / .htaccess
Created December 14, 2015 13:45
htaccess
# Necessary to prevent problems when using a controller named "index" and having a root index.php
# more here: http://httpd.apache.org/docs/2.2/content-negotiation.html
Options -MultiViews
# Activates URL rewriting (like myproject.com/controller/action/1/2/3)
RewriteEngine On
# Prevent people from looking directly into folders
Options -Indexes
@N-Porsh
N-Porsh / gist:7232626
Last active December 26, 2015 23:48
PHP: language system - json2Array
<?php
//session_start();
header('Cache-control: private'); // IE 6 FIX
function showUrl($lang){
$url = basename($_SERVER['REQUEST_URI']);
if(isset($_GET['page'])){
$url = "?page=".$_GET['page'];
$url .="&lang=".$lang;
@N-Porsh
N-Porsh / gist:7232908
Last active December 26, 2015 23:49
JavaScript: check if number
function isNumeric(n) {
return !isNaN(parseFloat(n)) && isFinite(n);
}
@N-Porsh
N-Porsh / gist:7247597
Last active December 27, 2015 01:49 — forked from vbaert/emailimage.php
PHP: image in email
<?php
if(isset($_GET['uid']) && isset($_GET['mid'])){
$mailid = (int)$_GET['mid'];
$userid = (int)$_GET['uid'];
$db = new mysqli_connect('databaseserver', 'databaseuser', 'databasepassword', 'databasename');
$db->query("INSERT INTO mailreaders (mailid, userid) VALUES ($mailid, $userid)");
$im=imagecreatetruecolor(1,1);
@N-Porsh
N-Porsh / gist:7301970
Last active December 27, 2015 09:09
JavaScript: form reset
$('#e_form').each(function() {
this.reset(); //Here form fields will be cleared.
});
@N-Porsh
N-Porsh / gist:7318827
Last active December 27, 2015 11:29
PHP: MySQLi connection template
<?php
/* CONFIG */
define("DB_HOST", "localhost");
define("DB_USER", "root");
define("DB_PASS", "");
define("DB_DATABASE", "my_db");
/* CONNECTION */