Skip to content

Instantly share code, notes, and snippets.

@weivall
weivall / gist:2489960
Created April 25, 2012 14:07
Prevent click-jacking
$(document).ready(function() {
// Prevent click-jacking
if (top != self) {
$('body').html('<h1>Unauthorized</h1>')
}
});
//// ============
try {
@weivall
weivall / gist:2519022
Created April 28, 2012 13:17
navigator.userAgent
if( navigator.userAgent.match(/Android/i)
|| navigator.userAgent.match(/webOS/i)
|| navigator.userAgent.match(/iPhone/i)
|| navigator.userAgent.match(/iPad/i)
|| navigator.userAgent.match(/iPod/i)
|| navigator.userAgent.match(/BlackBerry/i)
#!/bin/bash -e
# Define common variables
USERNAME=redmine
WWW_USERNAME=redmine
RUN_WITH_USERNAME="sudo -iu $USERNAME http_proxy=$http_proxy https_proxy=$https_proxy"
# Create user with $USERNAME
id $USERNAME || sudo useradd -rm $USERNAME
@weivall
weivall / gist:2595515
Created May 4, 2012 15:26
<meta name="format-detection" content="address=no;email=no" />
<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no, width=device-width">
<meta name="format-detection" content="address=no;email=no" />
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="ru" class="m-locale_ru m-layout_2pane" xml:lang="ru">
@weivall
weivall / gist:2780773
Created May 24, 2012 10:38
mod_expires
FileETag MTime Size
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript application/x-javascript
<ifModule mod_expires.c>
ExpiresActive On
ExpiresDefault "access plus 1 seconds"
ExpiresByType text/html "access plus 1 seconds"
ExpiresByType image/x-icon "access plus 2592000 seconds"
ExpiresByType image/gif "access plus 2592000 seconds"
user www-data www-data;
worker_processes 2;
error_log logs/error.log debug;
pid logs/nginx.pid;
events {
worker_connections 1024;
}
@weivall
weivall / gist:3225920
Created August 1, 2012 11:21
function is_url($url)
function is_url($url) {
return preg_match('|^http(s)?://[a-z0-9-]+(.[a-z0-9-]+)*(:[0-9]+)?(/.*)?$|i', $url);
}
@weivall
weivall / gist:3305323
Created August 9, 2012 15:50
isValidURL
function isValidURL(url){
return /^(([\w]+:)?\/\/)?(([\d\w]|%[a-fA-f\d]{2,2})+(:([\d\w]|%[a-fA-f\d]{2,2})+)?@)?([\d\w][-\d\w]{0,253}[\d\w]\.)+[\w]{2,4}(:[\d]+)?(\/([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)*(\?(&amp;?([-+_~.\d\w]|%[a-fA-f\d]{2,2})=?)*)?(#([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)?$/.test(url);
@weivall
weivall / gist:3305329
Created August 9, 2012 15:51
isValidEmail
function isValidEmail(email){
return /^((([a-z]|[0-9]|!|#|$|%|&|'|\*|\+|\-|\/|=|\?|\^|_|`|\{|\||\}|~)+(\.([a-z]|[0-9]|!|#|$|%|&|'|\*|\+|\-|\/|=|\?|\^|_|`|\{|\||\}|~)+)*)@((((([a-z]|[0-9])([a-z]|[0-9]|\-){0,61}([a-z]|[0-9])\.))*([a-z]|[0-9])([a-z]|[0-9]|\-){0,61}([a-z]|[0-9])\.)[\w]{2,4}|(((([0-9]){1,3}\.){3}([0-9]){1,3}))|(\[((([0-9]){1,3}\.){3}([0-9]){1,3})\])))$/.test(email);
}