Skip to content

Instantly share code, notes, and snippets.

View marteinn's full-sized avatar
✖️
🥕

Martin Sandström marteinn

✖️
🥕
View GitHub Profile
@marteinn
marteinn / gist:665521
Created November 6, 2010 16:27
Manipulating wordpress the_loop - merging a original query with external posts.
<?php
// Run original query, exclude category (in our case 4)
query_posts( "showposts=40&cat=-4");
$wp_query->get_posts(); // this will force the query to run
// Grab different data, in our case, data from our twitter category
$twitter = get_posts( "cat=4&showposts=3");
// Then we insert posts into $wp_query->posts using a loop and splice
@marteinn
marteinn / Remove SVN.scpt
Created July 4, 2011 17:52
Remove SVN - Applescript droplet
on open current_files
repeat with current_file in current_files
-- validate if the file as a folder
if (current_file as string) ends with ":" then
try
set current_file_path to (POSIX path of the current_file as string)
do shell script "find '" & current_file_path & "' -name '.svn' | xargs rm -Rf"
@marteinn
marteinn / wp-posts_where-sample.php
Created July 7, 2011 08:53
Wordpress - how to filter posts by date (using query parameters as hook arguments)
<?php
// Create hook funktion that alters the sql. It takes two args. $where (the sql string) and $wp_query (which is the actual query and holds the args for the function, $beinDate and $endDate).
function posts_where_hook( $where = '', $wp_query )
{
$beginDate = $wp_query->get("beginDate");
$endDate = $wp_query->get("endDate");
$where .= " AND post_date >= '".$beginDate."' AND post_date < '".$endDate."'";
@marteinn
marteinn / emitters.py
Created March 11, 2012 23:52
Piston - HTMLEmitter for Django-debug-toolbar
# http://tentacles.posterous.com/using-django-debug-toolbar-with-piston
from piston.emitters import Emitter
from django.http import HttpResponse
from django.utils import simplejson
from django.core.serializers.json import DateTimeAwareJSONEncoder
class HTMLEmitter( Emitter ):
def render( self, request ):
data = self.construct()
@marteinn
marteinn / jquery.boilerplate.js
Created May 3, 2012 22:21
jquery-boilerplate - Bugfix, methods will now return a value.
/*
* Project:
* Description:
* Author:
* License:
*/
// the semi-colon before function invocation is a safety net against concatenated
// scripts and/or other plugins which may not be closed properly.
;(function ( $, window, undefined ) {
@marteinn
marteinn / get_list_value.py
Last active October 4, 2015 10:58
get_list_value - Customtag (for Django)
from django import template
from django.template import Node, resolve_variable
from django.template.base import Variable
__author__ = 'martinsandstrom'
register = template.Library()
"""
This custom tag appends values onto a get var, with a delimiter. Like a list.
@marteinn
marteinn / jquery.parseparams.js
Created May 28, 2012 13:10 — forked from kares/jquery.parseparams.js
jQuery.parseParams - parse query string paramaters into an object (jshint compatible)
/**
* $.parseParams - parse query string paramaters into an object.
*/
/*jshint regexp: false */
(function($) {
var re = /([^&=]+)=?([^&]*)/g;
var decodeRE = /\+/g; // Regex for replacing addition symbol with a space
var decode = function (str) { return decodeURIComponent( str.replace(decodeRE, " ") ); };
$.parseParams = function(query) {
var params = {}, e;
@marteinn
marteinn / backbone.dryrun.js
Created August 22, 2012 17:20
Backbone.dryRun (Trigger route without effecting Backbone history)
/**
* Licensed under the MIT License
*
* DryRun is a Backbone.js addon that allows you to trigger route handler by suppling a url segment.
* without effecting Backbone history. (For those rare occations.)
*
* Usage:
* var fragment = window.location.pathname.substr(1, window.location.pathname.length);
* Backbone.dryRun(fragment);
**/
@marteinn
marteinn / api.py
Created September 8, 2012 14:33
Tastypie and ApiToken resource example
from tastypie.exceptions import NotFound
from tastypie.resources import ModelResource
from tastypie.authentication import BasicAuthentication, ApiKeyAuthentication
from tastypie.models import ApiKey
from django.contrib.auth.models import User
__author__ = 'martinsandstrom'
class ApiTokenResource(ModelResource):
@marteinn
marteinn / email_disposable.py
Created September 11, 2012 14:30
email_disposable.py - Validate if email is disposable
__author__ = 'martinsandstrom'
"""
SOURCE:
Most of the sources come from:
http://torvpn.com/temporaryemail.html
USAGE:
import email_disposable