Skip to content

Instantly share code, notes, and snippets.

@jinqian
jinqian / common.java
Created October 15, 2013 14:34
Common usage in android
// get screen size
int screenHeight = getResources().getDisplayMetrics().heightPixels;
int screenWidth = getResources().getDisplayMetrics().widthPixels;
@jinqian
jinqian / file_helper.java
Created November 26, 2013 12:43
list/find file using regex
String original = "*meta";
String regex = original.replace("?", ".?").replace("*", ".*?");
if (file.exists()) {
File[] children = file.listFiles();
for (File s : children) {
Log.i("FilePath", s.getName());
if (s.getName().matches(regex))
Log.i("FilePath", "Match: " + s.getName());
}
@jinqian
jinqian / Lawnchair.js
Created January 15, 2014 17:19
a very clean way to make sure your object is called as a constructor !
var Lawnchair = function (options, callback) {
// ensure Lawnchair was called as a constructor
if (!(this instanceof Lawnchair)) return new Lawnchair(options, callback);
// ...
}
@jinqian
jinqian / progressbar.xml
Last active August 29, 2015 13:57
android progress bar style
<!-- This is the case when you define the style in your style.xml -->
<ProgressBar
android:id="@+id/background_sync_indicator"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/overlay_info_cache"
android:layout_marginBottom="-6dp"
android:indeterminate="true"
android:visibility="gone" />
@jinqian
jinqian / delete_file.java
Created March 19, 2014 16:50
delete file in fir directory
String fn = "filename_pattern";
File dir = getFilesDir();
for (File f : dir.listFiles()) {
if (f.getName().contains(fn)) {
f.delete();
}
}
@jinqian
jinqian / onDraw.java
Created March 20, 2014 16:45
draw different shaped in android
@Override
public void onDraw(Canvas canvas) {
if (positionSet) {
float x0 = (float) (mCentralPoint.x - check.getWidth() / 2);
float y0 = (float) (mCentralPoint.y - check.getHeight() / 2);
// draw circle
canvas.drawCircle((float) mCentralPoint.x, (float) mCentralPoint.y, (float) size, mPaint);
@jinqian
jinqian / update.md
Created April 7, 2014 10:46
Mavericks

Homebrew

  • brew update
  • brew doctor
  • brew upgrade

Ruby

  • Get rid of RVM totally
  • Use rbevn instead
@jinqian
jinqian / aboutme.json
Created April 16, 2014 15:32
aboutme json format
{
"plan": "Enterprise",
"kid": "ddynrnyrf3irxxhkqk39",
"counts": {
"offline": {
"default": 2
},
"online": 4
},
"appname": "artgeek",
@jinqian
jinqian / wine.py
Created May 18, 2014 15:46
wine model
#!/usr/bin/env python
class Wine():
def __init__(self):
self.name = None
self.price = None
self.country = None
self.region = None
@jinqian
jinqian / ts.py
Last active August 29, 2015 14:03
generate unix time stamp w/ time delta
import datetime
import calendar
future = datetime.datetime.utcnow() + datetime.timedelta(days=14)
ts = calendar.timegm(future.timetuple())
print ts