Skip to content

Instantly share code, notes, and snippets.

@lilac
lilac / index.html
Last active August 29, 2015 14:21 — forked from anonymous/index.html
Ember render with promise
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Ember Starter Kit</title>
<link rel="stylesheet" href="http://cdnjs.cloudflare.com/ajax/libs/normalize/2.1.0/normalize.css">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="http://builds.handlebarsjs.com.s3.amazonaws.com/handlebars-v1.3.0.js"></script>
<script src="http://builds.emberjs.com/tags/v1.8.0/ember.js"></script>
<style id="jsbin-css">
@lilac
lilac / post-receive
Created May 23, 2015 10:17
Git deploy
#!/bin/bash
function pychanged {
git diff --name-only $1 $2 |grep -q ".py$"
}
while read oldrev newrev ref
do
branch=`echo $ref | cut -d/ -f3`
if [ "production" == "$branch" -o "master" == "$branch" ]; then
@lilac
lilac / promise.html
Created May 24, 2015 23:45
Ember PromiseProxyMixin
<!DOCTYPE html>
<!--
Created using JS Bin
http://jsbin.com
Copyright (c) 2015 by anonymous (http://jsbin.com/hizoperevo/1/edit)
Released under the MIT license: http://jsbin.mit-license.org
-->
<meta name="robots" content="noindex">
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:angle="0"
android:startColor="#f00"
android:centerColor="@android:color/transparent"
android:centerX="0.01" />
</shape>
public class OptionLayout extends LinearLayout
{
@InjectView(R.id.title)
TextView title;
@InjectView(R.id.summary)
TextView summary;
@InjectView(R.id.content)
ViewGroup content;
@lilac
lilac / radio_button.xml
Created July 24, 2015 04:21
Make radio button display the radio on the right
<style name="OptionRadioButton">
<item name="android:button">@android:color/transparent</item>
<item name="android:drawableRight">?android:listChoiceIndicatorSingle</item>
</style>
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<stroke
android:color="#000000"
android:width="2dp"/>
<corners android:radius="6dp"/>
</shape>
@lilac
lilac / RoundShapeDrawable.java
Created July 27, 2015 23:53
Create a rounded color drawable with a border
// This snippet is from http://stackoverflow.com/questions/17667964/how-to-create-shape-with-solid-corner-stroke-in-java-code
int strokeWidth = 5; // 3px not dp
int roundRadius = 15; // 8px not dp
int strokeColor = Color.parseColor("#2E3135");
int fillColor = Color.parseColor("#DFDFE0");
GradientDrawable gd = new GradientDrawable();
gd.setColor(fillColor);
gd.setCornerRadius(roundRadius);
Bitmap bitmap = Bitmap.createBitmap(pageWidth, pageHeight, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
// inflate a view
View view = LayoutInflater.from(context).inflate(R.layout.view, null);
int marginLeft = 100;
int marginTop = 100;
Rect bound = new Rect(marginLeft, marginTop, pageWidth - marginLeft, pageHeight - marginTop);
//Measure the view at the exact dimensions (otherwise the text won't center correctly)
int widthSpec = View.MeasureSpec.makeMeasureSpec(bound.width(), View.MeasureSpec.EXACTLY);
int heightSpec = View.MeasureSpec.makeMeasureSpec(bound.height(), View.MeasureSpec.EXACTLY);
@lilac
lilac / margins.html
Last active September 29, 2015 23:44
Margins trap in android
GridLayoutManager does not respect children's layout parameters. It sends measure spec as `EXACTLY` to children's `onMeasure` method.
You could wrap each children in a layout like FrameLayout.
ViewPager does not respect its children's margin settings. To have margins, wrap your children in a FrameLayout.