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 / 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:7316259
Last active July 25, 2016 12:46
CSS: css template
@charset "utf-8";
@import "reset.css";
/* GLOBAL CSS
-------------------------------------------------- */
/* RESPONSIVE CSS
-------------------------------------------------- */
@N-Porsh
N-Porsh / gist:7316280
Last active November 1, 2019 15:12
CSS: reset css
/* http://meyerweb.com/eric/tools/css/reset/
v2.0 | 20110126
License: none (public domain)
*/
html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
@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 */
@N-Porsh
N-Porsh / gist:7525543
Last active December 28, 2015 15:59
PHP: password generator
function random_password($chars = 8) {
$letters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.-+=_,!@$#*%<>[]{}';
return substr(str_shuffle($letters), 0, $chars);
}
@N-Porsh
N-Porsh / gist:7544681
Created November 19, 2013 12:33
JavaScript: getURLParam
function getURLParameter(name) {
return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.search)||[,""])[1].replace(/\+/g, '%20'))||null;
}
@N-Porsh
N-Porsh / gist:7766039
Last active June 7, 2019 01:10
PHP: simple multiple file upload
<?php
$max_file_size = 5*1024*1024; //5MB
$path = "admin/upload/"; // Upload directory
//$count = 0; // nr.successfully uploaded files
$valid_formats = array("rar","zip","7z","pdf","xlsx","xls","docx","doc","txt");
$valid_formats_server = array(
"application/pdf",
"application/octet-stream",