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 / validation.js
Created June 7, 2020 09:12
Vanilla JS Reset-form validation
(function () {
let password = document.getElementById("password");
let confirmPass = document.getElementById("confirm_password");
let submit = document.getElementById("submit");
function isPasswordStrong() {
const pattern = /^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.{8,})/g;
return pattern.test(password.value);
}
@N-Porsh
N-Porsh / wait-for-it.sh
Created April 16, 2020 12:28
wait for loading db container
#!/bin/sh
echo "Waiting for postgres..."
while ! nc -z database 5432; do
sleep 0.1
done
echo "PostgreSQL started"
@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: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",
@N-Porsh
N-Porsh / gist:7786887
Last active January 8, 2017 13:46
PHP: Simple Fast file uploader
<?php
//Loop through each file
for($i=0; $i<count($_FILES['files']['name']); $i++) {
//Get the temp file path
$tmpFilePath = $_FILES['files']['tmp_name'][$i];
//Make sure we have a filepath
if ($tmpFilePath != ""){
//Setup our new file path
$newFilePath = "admin/upload/" . $_FILES['files']['name'][$i];
@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 / arr2json.php
Last active January 3, 2016 23:39
arr2jsonUTF8
<?php
function array2json($arr) {
$parts = array();
$is_list = false;
if (!is_array($arr)) return;
if (count($arr)<1) return '{}';
//Find out if the given array is a numerical array
$keys = array_keys($arr);
@N-Porsh
N-Porsh / gist:7909530
Created December 11, 2013 12:26
PHP: files to ZIP
<?php
if(isset($_GET['id']) && $_GET['id'] != ''){
$usr_dir = "upload/".$_GET['id']."/";
$error = "";
//checking if zip module loaded
if(extension_loaded('zip')){
$zip = new ZipArchive(); // подгружаем библиотеку zip
$zip_name = time().".zip"; // имя файла
if($zip->open($zip_name, ZIPARCHIVE::CREATE)!==TRUE){
@N-Porsh
N-Porsh / uploader.js
Last active December 30, 2015 11:39
JavaScript: File uploader validator
<script>
function unique(arr) {
var obj = {};
for(var i=0; i<arr.length; i++) {
var str = arr[i];
obj[str] = true; // запомнить строку в виде свойства объекта
}
return Object.keys(obj); // или собрать ключи перебором для IE<9
@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;
}