Skip to content

Instantly share code, notes, and snippets.

View solancer's full-sized avatar
🎯
Focusing

Srinivas Gowda solancer

🎯
Focusing
View GitHub Profile
@solancer
solancer / jquery.validate.js
Created December 1, 2016 12:11
jquery validate rules
// Validation wrappe init & rules
$("#form").validate({
errorClass: 'invalid',
validClass: 'valid',
errorPlacement: function(error, element) {
error.insertAfter($(element));
// error.insertAfter($(element).siblings('label'));
},
rules: {
'name': {
@solancer
solancer / input.filters.js
Created December 1, 2016 12:05
HTML input filters
<script type="text/javascript">
$(document).ready(function() {
var masks = {
'int': /[\d]/,
'float': /[\d\.]/,
'money': /[\d\.\s,]/,
'num': /[\d\-\.]/,
'hex': /[0-9a-f]/i,
'email': /[a-z0-9_\.\-@]/i,
@solancer
solancer / randIdGen.js
Created December 1, 2016 11:35
Random id generator
function randIdGen() {
var text = "";
var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
for( var i=0; i < 5; i++ )
text += possible.charAt(Math.floor(Math.random() * possible.length));
return '#' + text;
}
@solancer
solancer / Country-List-with-ISD-codes.json
Created November 24, 2016 10:49
Country List with ISD codes
[
{
"name":"United Arab Emirates",
"dial_code":"+971",
"code":"AE"
},
{
"name":"Afghanistan",
"dial_code":"+93",
"code":"AF"
@solancer
solancer / param.js
Created August 11, 2016 15:06
Javascript Params
function setURLParam(key, value) {
var re = new RegExp("([?&])" + key + "=.*?(&|#|$)(.*)", "i");
var newSearch = location.search;
// Is the key-value pair present in the existing search?
if (re.test(newSearch)) {
// Update a value
newSearch = newSearch.replace(re, '$1' + key + "=" + value + '$2$3');
} else {
// Add the key and its value
@solancer
solancer / srini.js
Created July 28, 2016 05:58
www-with-node-js-and-express
var express = require("express");
var app = express.createServer();
var port = 9090;
app.all(/.*/, function(req, res, next) {
var host = req.header("host");
if (host.match(/^www\..*/i)) {
next();
} else {
res.redirect(301, "http://www." + host);
@solancer
solancer / apache-nginx-ftp
Created July 27, 2016 10:53
Correct permissions for /var/www/html
// Adding current user to www-data
sudo adduser $USER www-data
//change ownership to user:www-data and
sudo chown $USER:www-data -R /var/www/html
sudo chmod u=rwX,g=srX,o=rX -R /var/www/html
// change file permissions of existing files and folders to 755/644
sudo find /var/www/html -type d -exec chmod g=rwxs "{}" \;
@solancer
solancer / email-input-pattern.html
Created June 21, 2016 20:41
Email HTML regex pattern
<input type="text"
pattern="[a-zA-Z0-9_]+(?:\.[A-Za-z0-9!#$%&amp;'*+/=?^_`{|}~-]+)*@(?!([a-zA-Z0-9]*\.[a-zA-Z0-9]*\.[a-zA-Z0-9]*\.))(?:[A-Za-z0-9](?:[a-zA-Z0-9-]*[A-Za-z0-9])?\.)+[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?"
required>
@solancer
solancer / mod_pagespeed .htaccess
Last active December 1, 2024 00:09
mod_pagespeed .htaccess configuration
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access 1 year"
ExpiresByType image/jpeg "access 1 year"
ExpiresByType image/gif "access 1 year"
ExpiresByType image/png "access 1 year"
ExpiresByType text/css "access 1 month"
ExpiresByType text/html "access 1 month"
ExpiresByType application/pdf "access 1 month"
ExpiresByType text/x-javascript "access 1 month"
@solancer
solancer / jquery.validate.boilerplate.js
Created May 8, 2016 20:12
My jquery.validate.boilerplate.js
// initialize validate plugin on the form
$('#contact-form').validate({
errorPlacement: function (error, element) {
var lastError = $(element).data('lastError'),
newError = $(error).text();
$(element).data('lastError', newError);
if(newError !== '' && newError !== lastError){