Skip to content

Instantly share code, notes, and snippets.

@dingzhihu
dingzhihu / MainActivity
Created March 12, 2015 02:45
test loader using robolectric
public class MainActivity extends FragmentActivity implements LoaderManager.LoaderCallbacks<String> {
public boolean onCreateLoaderExecuted;
public boolean onLoadFinishedExecuted;
public boolean loadInBackgroundExecuted;
@Override
protected void onCreate(Bundle savedInstanceState) {
@dingzhihu
dingzhihu / MyActivity.java
Last active December 28, 2015 15:28
create custom selector
package com.example.HelloAndroid;
import android.app.Activity;
import android.os.Bundle;
import com.example.HelloAndroid.widget.MyTextView;
public class MyActivity extends Activity {
/**
* Called when the activity is first created.
<manifest ...>
...
<!-- Make sure your app (or individual activity) uses the
theme with the custom attribute defined. -->
<application android:theme="@style/AppTheme" ...>
...
</application>
</manifest>
@dingzhihu
dingzhihu / file.rb
Created August 29, 2013 14:09
A guide to Python packaging
http://www.ibm.com/developerworks/opensource/library/os-pythonpackaging/

Sublime Text 2 – Useful Shortcuts (PC)

Loosely ordered with the commands I use most towards the top. Sublime also offer full documentation.

Editing

Ctrl+C copy current line (if no selection)
Ctrl+X cut current line (if no selection)
Ctrl+⇧+K delete line
Ctrl+↩ insert line after
@dingzhihu
dingzhihu / WordGridView.java
Created March 14, 2013 07:08
WordGridView not a ViewGroup
package com.meituan.android.widget;
import android.content.Context;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.View;
@dingzhihu
dingzhihu / pom.xml
Created February 22, 2013 09:53
android app phonetocomputer pom
<?xml version="1.0" encoding="UTF-8"?>
<project
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<name>PhoneToComputer</name>
<groupId>com.dingzhihu.android</groupId>
<artifactId>phonetocomputer</artifactId>
<version>1.0-SNAPSHOT</version>
@dingzhihu
dingzhihu / .gitignore
Last active December 14, 2015 01:18
gitignore file when dev android under intellij
.idea
*.iml
gen/
local.properties
build.xml
bin
out
@dingzhihu
dingzhihu / singleton_methods.rb
Created November 13, 2012 12:26 — forked from samnang/singleton_methods.rb
Different ways to define singleton methods
##############################################
# Different ways to define singleton methods #
##############################################
def test_singleton_method
animal = 'dog'
yield animal
puts animal.speak
@dingzhihu
dingzhihu / gem-create.rb
Created September 28, 2012 08:29
create gem automatically
#!/usr/bin/env ruby -w
#Usage: ./gem-create.rb your_gem_name
def dump(file_name, content, executable = false)
content ||= ''
lines = content.split('\n')
File.open(file_name, 'w') do |f|
lines.each do |line|
f.puts line