Skip to content

Instantly share code, notes, and snippets.

@alxscms
alxscms / print_model.py
Created January 5, 2016 15:14
Print all attributes of a django model with colors
def print_model(object):
print "\033[96m<{0}>\033[0m".format(wp.__class__.__name__)
for field in object._meta.fields:
if field.value_to_string(object) != 'None' and field.value_to_string(object) != '':
print "\033[94m{0:30}\033[0m \033[93m{1}\033[0m".format(field.name, field.value_to_string(object))
else:
print "{0:30} {1}".format(field.name, field.value_to_string(object))
// true if display none or visibility hidden
function isVisible(el) {
var style = window.getComputedStyle(el);
return (style.display !== 'none')
}
// return true if element is in the window bounds or false if outside
function isInWindow(el) {
var viewportOffset = el.getBoundingClientRect();
// these are relative to the viewport
@alxscms
alxscms / .bash_profile
Last active August 29, 2015 14:20
Bash script for gitignore.io with autocompletion, to paste in .bash_profile
# gitignore function working with gitignore.io
function gitignore() {
local IFS=",";
if [[ "$#" -eq 0 ]]; then
echo "gitignore: try 'gitignore --help' for more information"
elif [[ "$1" == "--help" || "$1" == "-h" ]]; then
echo "Usage: gitignore [options] <arguments separated by spaces>"
echo " -h, --help: show help"
echo " -l, --list: list all possible arguments"
echo " -s, --save: save the output to a .gitignore file"
@alxscms
alxscms / BlurPicassoTransformation.java
Created February 9, 2015 13:46
Picasso transformation that crops center the image to the specified dimensions and blurs it
public class BlurPicassoTransformation implements Transformation {
private Context mContext;
private int mWidth;
private int mHeight;
public BlurPicassoTransformation(Context context, int width, int height) {
mContext = context;
mWidth = width;
mHeight = height;
@alxscms
alxscms / AutoResizeTextView.java
Created February 9, 2015 13:45
TextView that gets its text size refined to fit the available space
import android.annotation.TargetApi;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.RectF;
import android.os.Build;
import android.text.Layout.Alignment;
import android.text.StaticLayout;
import android.text.TextPaint;
import android.util.AttributeSet;
import android.util.SparseIntArray;
@alxscms
alxscms / StrokeOverlayImageView.java
Last active August 29, 2015 14:15
An image view with an inner stroke overlaying the actual image
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.widget.ImageView;
public class StrokeOverlayImageView extends ImageView {
private final int DEFAULT_BORDER_COLOR = 0x26000000;
@alxscms
alxscms / AbstractView.java
Created February 8, 2015 18:34
An abstract view simplifying the creation of Android widgets by scaling the canvas to the right size (following the device density), translating it following the set padding and by taking into account the view padding in the measurements
import android.content.Context;
import android.graphics.Canvas;
import android.util.AttributeSet;
import android.view.View;
public abstract class AbstractView extends View {
private float mOffsetX;
private float mOffsetY;
@alxscms
alxscms / CollapseAnimation.java
Created February 8, 2015 18:31
Android expand & collapse animation
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.Transformation;
public class CollapseAnimation extends Animation implements Animation.AnimationListener {
private View mView;
private int mInitialHeight;
private boolean mAnimating;
@alxscms
alxscms / CircleTransform.java
Last active August 29, 2015 14:14 — forked from julianshen/CircleTransform.java
Circle transformation for Picasso library, working with GIF files
/*
* Copyright 2014 Julian Shen
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software