Skip to content

Instantly share code, notes, and snippets.

Sune Fengel fengelz

View GitHub Profile
@fengelz
fengelz / gist:6377400
Created Aug 29, 2013
Codeigniter htaccess file that remoces index.php and allows resources
View gist:6377400
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
AddDefaultCharset utf-8
AddType image/svg+xml svg svgz
AddEncoding gzip svgz
@fengelz
fengelz / preventscroll.js
Created Aug 8, 2013
Enable/Disable scrolling temporarily when needed window.scrollStopper.disableScroll(); window.scrollStopper.enableScroll();
View preventscroll.js
window.scrollStopper = (function () {
var obj = {}
obj.keys = [
37, 38, 39, 40
];
obj.preventDefault = function (e) {
e = e || window.event;
if (e.preventDefault) {
e.preventDefault();
}
@fengelz
fengelz / frontend.js
Created Mar 28, 2012
Wordpress ajax sign in
View frontend.js
//Your frontend javascript
var data = {
action: 'sign_in',
username:"<username>",
pass:"<password>"
};
jQuery.post('/wordpress/wp-admin/admin-ajax.php', data,
function(response) {
alert("signed in successfully");
@fengelz
fengelz / functions.php
Created Mar 21, 2012
Redirect to first child in wordpress
View functions.php
/*if($post has condition) {
redirect_first_child($post->ID);
}*/
function redirect_first_child($post_id) {
$pagekids = get_pages("child_of=".$post_id."&sort_column=menu_order");
if ($pagekids) {
$firstchild = $pagekids[0];
wp_redirect(get_permalink($firstchild->ID));
exit;
@fengelz
fengelz / functions.php
Created Mar 21, 2012
Get page depth in wordpress
View functions.php
function get_page_depth($post) {
$parent_id = $post->post_parent;
$depth = 0;
while ($parent_id > 0) {
$page = get_page($parent_id);
$parent_id = $page->post_parent;
$depth++;
}
return $depth;
@fengelz
fengelz / Email Validation
Created Feb 20, 2012
Javascript email validation. Validated with JSONLint.
View Email Validation
var isEmail = function(a){return (/^[\w\.%\+\-]+@(?:[A-Z0-9\-]+\.)+(?:[A-Z]{2,6})$/i).test(a);};
@fengelz
fengelz / jsprinthtml.js
Created Jan 25, 2012
Javascript print html.
View jsprinthtml.js
function printcontent(content)
{
var mywindow = window.open('', '', '');
mywindow.document.write('<html><title>Print</title><body>');
mywindow.document.write(content);
mywindow.document.write('</body></html>');
mywindow.document.close();
mywindow.print();
return true;
}
@fengelz
fengelz / gethashvalue.js
Created Jan 19, 2012
javascript get hash value
View gethashvalue.js
var hashval = location.hash.replace('#', '').substring(0, location.hash.indexOf('?')-1);
@fengelz
fengelz / hascanvas.js
Created Dec 5, 2011
Detect html canvas with javascript
View hascanvas.js
function hasCanvas()
{
return !!document.createElement('canvas').getContext;
}
@fengelz
fengelz / umbraco404httpmodule.cs
Created Nov 3, 2011
404 Http module for umbraco.
View umbraco404httpmodule.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using System.Web;
using umbraco.BusinessLogic;
using umbraco.NodeFactory;
namespace Web.Modules
{
You can’t perform that action at this time.