Skip to content

Instantly share code, notes, and snippets.

View marteinn's full-sized avatar
✖️
🥕

Martin Sandström marteinn

✖️
🥕
View GitHub Profile
@marteinn
marteinn / admin.js
Last active August 29, 2015 13:55
An example on how to register your own attachment as feature image from the Wordpress media lightbox.
// Pick up data from service.php and send returned data to wp ajax admin.
var win = window.dialogArguments || opener || parent || top
$.ajax({
url: ajaxurl,
type: "POST",
contentType: "application/x-www-form-urlencoded; charset=UTF-8",
data: postData,
@marteinn
marteinn / authorizeoauth.py
Created February 13, 2014 21:42
A django command for generating app access tokens for Discogs (using requests and requests_oauthlib).
from django.core.management import BaseCommand
from requests_oauthlib import OAuth1Session
__author__ = 'martinsandstrom'
class Command(BaseCommand):
def handle(self, *args, **options):
if len(args) != 2:
print "Invalid arguments"
@marteinn
marteinn / Gravatar.java
Last active August 29, 2015 13:56
This is a gravatar wrapper for Android (based upon http://sv.gravatar.com/site/implement/images/java/).
package se.marteinn.utils;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
public class Gravatar {
public static final String TAG = Gravatar.class.toString();
public static final String url = "http://www.gravatar.com/avatar/";
@marteinn
marteinn / external_tastypie_serialization.py
Last active August 29, 2015 14:00
How to use Tastypies resource serialization outside the api
"""
Credit to the parker library (https://github.com/coxmediagroup/parker/) and their TastyPieHandler.
"""
req = HttpRequest()
resource = YourResource()
bundle = resource.build_bundle(obj=your_model)
bundle = resource.full_dehydrate(bundle)
bundle = resource.alter_detail_data_to_serialize(req, bundle)
@marteinn
marteinn / discogs_ilove_checksum.py
Last active August 29, 2015 14:01
How to check for the "I love discogs" fallback image when requesting cover.
"""
The function check_if_blocked_image checks if passed checksum equals the "I love discogs" checksum.
Example:
import hashlib
checksum = hashlib.md5(result.content).hexdigest()
if check_if_blocked_image(checksum):
print "I love discogs is showing"
@marteinn
marteinn / tastypie_post_serialization.py
Created May 31, 2014 23:26
How to perform a task "post" tastypie serialization
class NotificationResource(ModelResource):
class Meta:
queryset = MyModel.objects.all()
resource_name = "mymodel"
authorization = Authorization()
authentication = ApiKeyAuthentication()
def dispatch(self, request_type, requenst, **kwargs):
# Grab response and suspend dispatch
response = super(ModelResource, self).dispatch(request_type,
@marteinn
marteinn / .gitignore
Created June 10, 2014 13:49
.gitignore - For android studio
# .gitignore - For android studio
# Based on: http://stackoverflow.com/a/21049338
# built application files
*.apk
*.ap_
# files for the dex VM
*.dex
@marteinn
marteinn / authorize_rdio.py
Created August 16, 2014 16:09
A Django command for authorizing application on Rdio (requires requests_oauthlib)
from django.core.management import BaseCommand
from requests_oauthlib import OAuth1Session
__author__ = 'martinsandstrom'
class Command(BaseCommand):
def handle(self, *args, **options):
"""
Authorizes a rdio application, requires consumer key and consumer access.
@marteinn
marteinn / .bashrc
Last active August 29, 2015 14:06
Initial install - A minimal vim/bash config. Reload bash: source ~/.bashrc
#
# Basic Setup
#
# From:
# https://gist.githubusercontent.com/marteinn/39cd2d37febbe9fd75a2/raw/.bashrc
#
# Installing:
# curl -L https://gist.githubusercontent.com/marteinn/39cd2d37febbe9fd75a2/raw/.bashrc > ~/.bashrc
alias ll='ls -alF'
@marteinn
marteinn / canvas-db:reset_encryption_key_hash-solution.md
Last active August 29, 2015 14:06
Canvas LSM - encryption key is incorrect + Could not find command "db:reset_encryption_key_hash"

Problem:

Cant get db:reset_encryption_key_hash to work under rvm?

>>> bundle _1.5.3_ exec script/server
...encryption key is incorrect. if you have intentionally changed it, you may want to run `rake db:reset_encryption_key_hash`...

>>> $GEM_HOME/bin/bundle _1.5.3_ db:reset_encryption_key_hash
Could not find command "db:reset_encryption_key_hash".