Skip to content

Instantly share code, notes, and snippets.

View timonweb's full-sized avatar

Tim Kamanin timonweb

View GitHub Profile
@timonweb
timonweb / sqldump_middleware.py
Created May 23, 2012 07:45 — forked from kesor/sqldump_middleware.py
Django SQL dump middleware
from django.conf import settings
from django.db import connection
class SqldumpMiddleware(object):
def process_response(self, request, response):
if settings.DEBUG and 'sqldump' in request.GET:
response.content = str(connection.queries)
response['Content-Type'] = 'text/plain'
return response
@timonweb
timonweb / gist:2777011
Created May 23, 2012 18:44
WSGI for Django 1.4
"""
WSGI config for fbhog project.
This module contains the WSGI application used by Django's development server
and any production WSGI deployments. It should expose a module-level variable
named ``application``. Django's ``runserver`` and ``runfcgi`` commands discover
this application via the ``WSGI_APPLICATION`` setting.
Usually you will have the standard Django WSGI application here, but it also
@timonweb
timonweb / Put this into template.php file
Created May 30, 2012 17:00
Override Read more link
/**
* Override Read more link
* @param unknown_type $vars
*/
function themename_preprocess_node(&$vars){
$vars['node']->links['node_read_more']['title'] = "read more";
$node = $vars['node'];
# Following code is from theme.inc's template_preprocess_node()
$vars['links'] = !empty($node->links) ? theme('links', $node->links, array('class' => 'links inline')) : '';
@timonweb
timonweb / gist:2867715
Created June 4, 2012 10:45
Check if user is a fan of a facebook page
FB.api("me/likes/SOME_ID", function(response) {
if ( response.data.length === 1 ) { //there should only be a single value inside "data"
console.log('You like it');
} else {
console.log("You don't like it");
}
});
@timonweb
timonweb / gist:3165322
Created July 23, 2012 18:38
Code to catch all PHP errors which result in 500 Error Code. Include this snippet at the beginning of index.php file
<?php
define('E_FATAL', E_ERROR | E_USER_ERROR | E_PARSE | E_CORE_ERROR |
E_COMPILE_ERROR | E_RECOVERABLE_ERROR);
define('ENV', 'dev');
//Custom error handling vars
define('DISPLAY_ERRORS', TRUE);
define('ERROR_REPORTING', E_ALL | E_STRICT);
class QuerySetDoubleIteration(Exception):
"A QuerySet was iterated over twice, you probably want to list() it."
pass
# "Skinny" here means we use iterator by default, rather than
# ballooning in memory.
class SkinnyManager(Manager):
def get_query_set(self):
return SkinnyQuerySet(self.model, using=self._db)
@timonweb
timonweb / Serving static files for Django on Webfaction
Created November 10, 2012 16:33
Serving static files for Django on Webfaction
# put after other LoadModule lines
LoadModule alias_module modules/mod_alias.so
LoadModule authz_host_module modules/mod_authz_host.so
LoadModule expires_module modules/mod_expires.so
...
<VirtualHost *:<webapp-port>>
...
# after WSGIScriptAlias
@timonweb
timonweb / gist:4110449
Created November 19, 2012 12:45
Generic htaccess redirect www to non-www
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
@timonweb
timonweb / gist:4145128
Created November 25, 2012 20:10 — forked from haf/gist:2843680
Get SSH working on Vagrant/Windows/Git

If you are using vagrant, you probably-statistically are using git. Make sure you have its binary folder on your path, because that path contains 'ssh.exe'.

Now, modify C:\vagrant\vagrant\embedded\lib\ruby\gems\1.9.1\gems\vagrant-1.0.3\lib\vagrant\ssh.rb to comment out the faulty Windows check and add a real SSH check:

# if Util::Platform.windows?
  # raise Errors::SSHUnavailableWindows, :host => ssh_info[:host],
                                       # :port => ssh_info[:port],
                                       # :username => ssh_info[:username],
 # :key_path =&gt; ssh_info[:private_key_path]
@timonweb
timonweb / put into apache httpd.d
Created December 1, 2012 19:34
do not allow .git version control files to be read
# do not allow .git version control files to be issued
<Directorymatch "^/.*/\.git+/">
Order deny,allow
Deny from all
</Directorymatch>
<Files ~ "^\.git">
Order allow,deny
Deny from all
</Files>