Skip to content

Instantly share code, notes, and snippets.

@kalinchernev
kalinchernev / gist:6867262
Last active December 24, 2015 21:39
JavaScript function to return an extension for a filename input as a string
// @params string - a string containing a file name
// @return string - the file extension (with no period) if it has one, otherwise false
function getFileExtension(string) {
if (typeof(string) === 'string' && (string.indexOf(".") !== -1)){
var dot=string.indexOf(".");
return string.substring(dot+1, i.length)
} else {
return false;
@kalinchernev
kalinchernev / positioning.css
Created October 23, 2013 08:05
Positioning demonstration page
/*
* static - default
* fixed - scrolls with the page
* absolute - top left is starting point
* relative - same as absolute, but starting from static position; Parent elements remain as they are.
* inherit - not well for older IE
*/
body {
background: #f6f6f6;
@kalinchernev
kalinchernev / fluid_box_inner_bottom_center.html
Created December 13, 2013 12:37
Fluid box with inner box on the bottom in the middle
<!DOCTYPE html>
<html>
<head>
<title>Fluid box with inner box on the bottom in the middle</title>
<style type="text/css">
.outer {
background: #ccc;
border: 1px solid red;
position: relative;
height: 250px;
@kalinchernev
kalinchernev / Form.class.php
Created January 20, 2014 11:14
Basic class to build a form from an array
<?php
/**
* Form Class
*
* Responsible for building forms
*
* @param array $elements renderable array containing form elements
*
* @return void
@kalinchernev
kalinchernev / WebDevSetup.sh
Last active January 4, 2016 00:28
Init for bash to setup LAMP environment on Ubuntu 12.04 64 bit
#!/bin/bash
# Start this script at newly installed Ubuntu 12.04 LTS
# The script will install all necessary software for setting up a web development environment
#
# Ubuntu fixes
# - Install the package to fix missing skype icon on toolbar
#
# LAMP environment
# - apache2
# - php5
@kalinchernev
kalinchernev / passwordValidator.js
Last active August 29, 2015 13:58
JavaScript password validator
/**
* Validates if the input for password field matches requirements for password strength
* @returns {void}
*/
function validatePassword() {
var inputValue;
var requirement = new RegExp("(^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[@#$%*]).{8,}$)");
// clear previous
jQuery(".reg-validate-message").remove();
@kalinchernev
kalinchernev / emailValidator.js
Created April 10, 2014 14:31
Email validators for javascript
/**
* Validates if the input for email field matches requirements and if it's a valid email
* @returns {void}
*/
function validateEmail() {
var inputValue;
// clear previous
jQuery(".reg-validate-email").remove();
@kalinchernev
kalinchernev / breadcrumb.php
Created April 15, 2014 13:35
Drupal helper to display the breadcrumbs - decoupled from the theme
<?php
/**
* Helper to display the breadcrumbs
* @return string Breadcrumbs markup
*/
function _display_breadcrubs() {
$breadcrumbs = drupal_get_breadcrumb();
return theme('breadcrumb', array('breadcrumb' => $breadcrumbs));
}
@kalinchernev
kalinchernev / index.html
Created June 5, 2014 14:01
Example user information bar, which re-sizes in width depending on the length of the user's name.
<!DOCTYPE html>
<!--[if lt IE 7 ]> <html dir="ltr" lang="en-US" class="no-js ie6"> <![endif]-->
<!--[if IE 7 ]> <html dir="ltr" lang="en-US" class="no-js ie7"> <![endif]-->
<!--[if IE 8 ]> <html dir="ltr" lang="en-US" class="no-js ie8"> <![endif]-->
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=9; IE=8; IE=7" />
<title>Resizable user info bar</title>
<style type="text/css">
@kalinchernev
kalinchernev / children.css
Created June 11, 2014 11:32
Selecting children elements in IE
/* equivalent to li:nth-child(1) */
#mainNav ul li:first-child a {
background: #1b77af;
width: 236px;
text-align: center;
margin-right: 10px;
}
/* equivalent to li:nth-child(2) */
#mainNav ul li:first-child + li a {
background: #33a0ff;