Skip to content

Instantly share code, notes, and snippets.

View elvisciotti's full-sized avatar

Elvis Ciotti elvisciotti

View GitHub Profile
@elvisciotti
elvisciotti / htaccess
Created January 21, 2013 12:14
.htaccess example to exclude one directory from subsequent rule
# skip admin directory
RewriteCond %{REQUEST_URI} !^/admin
# rule
RewriteRule ...
@elvisciotti
elvisciotti / createAuthArea.sh
Last active December 11, 2015 10:18
Instructions to create htaccess protected area with apache
# create an .htaccess file in the directory to protect
AuthUserFile /full/path/to/.htpasswd
AuthType Basic
AuthName "My Secret Folder"
Require valid-user
#create the password with this command
htpasswd -c /full/path/to/.htpasswd fred
# Now go to http://yourserver/protecteddir/ and insert username:fred, password (the one you inserted after the last command)
@elvisciotti
elvisciotti / gist:4585750
Created January 21, 2013 12:35
HTML meta code to refresh page after 5 seconds
<meta http-equiv="refresh" content="5;url=http://example.com/" />
@elvisciotti
elvisciotti / jsNotenabledWarning.html
Last active December 11, 2015 10:18
Simple HTML+JS code to display a warning when Javascript is not enabled
<!-- displays the following warning, then hide immediately with javascript.
If javascript is not enabled, the message will be displayed. No JQuery needed -->
<p id="jsenabled" style="color:red">Javascript must be enabled to use the form !</p>
<script type="text/javascript">
document.getElementById('jsenabled').innerHTML='';
document.getElementById('jsenabled').style.display = 'none';
</script>
@elvisciotti
elvisciotti / canonicalRedirect.htaccess
Last active December 11, 2015 10:18
Apache htaccess/virtualhost rule to redirect 301 non-www version to www-version (to avoid duplicate URLs on search engines) e.g. example.org/one/two -> www.example.org/one/two
# .htaccess or Apache vhost
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
@elvisciotti
elvisciotti / gist:7467264
Last active August 14, 2022 06:27
chrome launch without web security, custom user agent, data dir and web page
"/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome" --disable-web-security --user-agent="Android"  --user-data-dir="C:/temp-chrome-app" --app=file:///C:/path/to/app.html"
@elvisciotti
elvisciotti / cssReload.js
Last active December 29, 2015 17:29
browser toolbar link to reload CSS using JavaScript
javascript:var links=document.getElementsByTagName("link"); for (var i = 0; i < links.length;i++) { var link = links[i]; if (link.rel === "stylesheet") {link.href += "?"; }}; return false
@elvisciotti
elvisciotti / fileUploadMaxSize.js
Last active August 14, 2022 06:25
Attach a "onchange" listener to file upload elements for each form. If the selected file size invalid (bigger than input.MAX_FILE_SIZE, disable submit button and append a message
$(document).ready(function() {
/*
* Attach a "onchange" listener to file upload elements for each form.
* Behaviour:
* If the selected file size invalid (bigger than the value from the <input name="MAX_FILE_SIZE" /> element):
* - disable submit button
* - append a message (class="errors") to the form.
* If the selected file size is valid:
* - enable the submit button
* - remove the error message previously added
@elvisciotti
elvisciotti / etc-fileline-add.pp
Last active August 29, 2015 14:09
Puppet task to add a line into a file if not existing and not commented out (prefixed with "#")
# add STRING-XXXXXXX to FILE-YYYYYY
# if commented out, it gets re-added
exec { "[task name]":
command => '/bin/echo "STRING-XXXXXXX" >> FILE-YYYYYY',
unless => '/bin/grep -E "^STRING-XXXXXXX$" FILE-YYYYYY'
}
@elvisciotti
elvisciotti / gitcommit.bash
Last active November 13, 2015 16:25
bash function to commit a message prepending the branch name
# gitcommit this message will be commited, with the branch name prepended
# e.g. (on branch feature01)
# > gitcommit this is the commit message
# > Committed with message "feature01 this is the commit message"
gitcommit() {
gm_branch=$(git branch | sed -n -e 's/^\* \(.*\)/\1/p');
gm_commitMessage="${gm_branch} $@"
git commit -m "${gm_commitMessage}"
echo Committed with message \"$(git log -n1 --pretty=format:%s)\"
}