Skip to content

Instantly share code, notes, and snippets.

View marteinn's full-sized avatar
✖️
🥕

Martin Sandström marteinn

✖️
🥕
View GitHub Profile
@marteinn
marteinn / InteractiveScrollView.java
Last active October 10, 2015 14:17
InteractiveScrollView - Understanding when ScrollView has reached the bottom
package se.marteinn.ui;
import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ScrollView;
public class InteractiveScrollView extends ScrollView {
OnBottomReachedListener onBottomReachedListener;
@marteinn
marteinn / ScrollListView.java
Last active January 18, 2018 20:30
ScrollListView - Detect bottom reached for ListView
package se.marteinn.ui;
import android.content.Context;
import android.util.AttributeSet;
import android.widget.AbsListView;
import android.widget.ListView;
/**
* Triggers a event when scrolling reaches bottom.
@marteinn
marteinn / cache.js
Created December 2, 2012 22:25
Backbone.js + Local Connection cache example
/*global require, define, console, Modernizr */
define([
"jquery",
"backbone"
], function ($, Backbone) {
var storage = {};
if (Modernizr.localstorage) {
@marteinn
marteinn / sprite_2x.scss
Created January 9, 2013 09:15
Simple sass mixin that inserts a retina based sprite
// Resize and return image sprite
@mixin sprite-2x($map, $sprite, $show-bg: 1) {
$sprite-image: sprite-file($map, $sprite);
$sprite-width: image-width($sprite-image);
$sprite-positions: sprite-position($map, $sprite);
@media all and (-webkit-min-device-pixel-ratio : 1.5) {
@if $show-bg == 1 {
background-image: sprite-url($map);
}
@marteinn
marteinn / author_post_tag_cloud_tags.php
Last active December 12, 2015 03:08 — forked from anonymous/author_post_tag_cloud_tags.php
Show tag cloud in Wordpress with tags from a specific user (add in functions.php).
<?php
add_filter('widget_tag_cloud_args','author_post_tag_cloud_tags');
function author_post_tag_cloud_tags($args) {
# Show only on author section
if (is_author()) {
global $post;
$wp_query = new WP_Query("showposts=-1&author=".$post->post_author);
$author_tag_ids = array();
@marteinn
marteinn / gist:5546293
Created May 9, 2013 08:33
Quick example on how to replace the Flask-Admin homescreen.
from flask.ext.admin import Admin, expose, AdminIndexView
class HomeView(AdminIndexView):
@expose("/")
def index(self):
return self.render('admin/home.html')
admin = Admin(app, "MadeInStockholm.se", index_view=HomeView(name='Home'))
@marteinn
marteinn / gist:5693665
Last active September 20, 2017 23:42
Example on how to debug Tastypie using Django Debug Toolbar
def html_decorator(func):
"""
This decorator wraps the output in html.
(From http://stackoverflow.com/a/14647943)
"""
def _decorated(*args, **kwargs):
response = func(*args, **kwargs)
wrapped = ("<html><body>",
@marteinn
marteinn / save_image.php
Last active December 20, 2015 18:09
Example on how to download, save and insert image as a attachment to Wordpress from a web url.
<?php
/**
* Create image attachment using a web url.
*
* @param String url Url path to the image we want to add (http://test.com/img.jpg)
* @param String filename Name of file ex: image.jpg. Will otherwise be loaded by header.
* @param int post_id The post where image should be associated if featured
* is true. (Optiona)
* @param Boolean featured Whether a file should be featured or not. (Optional)
@marteinn
marteinn / showdelayedkeyboard.java
Last active January 2, 2016 03:59
How to delay opening of the keyboard on Android, put these methods in your activity.
private void showDelayedKeyboard (final View view) {
showDelayedKeyboard(view, 100);
}
private void showDelayedKeyboard (final View view, final int delay) {
new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... params) {
try {
Thread.sleep(delay);
@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,