Skip to content

Instantly share code, notes, and snippets.

View IanField90's full-sized avatar
:shipit:

Ian Field IanField90

:shipit:
View GitHub Profile
@IanField90
IanField90 / gist:1462823
Created December 11, 2011 21:23
Bulky - is there a better way? Ideally, 1 line.
<%
if @course == nil
@id = @programme.course_id
else
@id = @course.id
end
%>
<%= f.hidden_field :course_id, :value => @id %>
@IanField90
IanField90 / Textfilter
Created April 19, 2013 09:52
Filtering a listview in android
this.filterTextWatcher = new TextWatcher() {
public void afterTextChanged(Editable s) { }
public void beforeTextChanged(CharSequence s, int start, int count,
int after) { }
public void onTextChanged(CharSequence s, int start, int before, int count) {
adapter.getFilter().filter(s);
}
@IanField90
IanField90 / Scaling
Created June 19, 2013 13:16
Scaling
int pxDp = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 80, getResources().getDisplayMetrics());
int pxDp = (int) (getResources().getDisplayMetrics().density * px + 0.5f);

Keybase proof

I hereby claim:

  • I am IanField90 on github.
  • I am IanField90 (https://keybase.io/IanField90) on keybase.
  • I have a public key whose fingerprint is 4840 AC58 BE03 D6DB 0C9A 22B4 CDF7 3AB9 750A 2C32

To claim this, I am signing this object:

@IanField90
IanField90 / MyActivity.java
Last active August 29, 2015 14:06
Android Wear
public class MyActivity extends Activity {
private TextView mTextView;
private ImageView mLogo;
private ImageView mStars;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my);
@IanField90
IanField90 / build.gradle
Created March 5, 2015 11:07
Automatic build numbers and version name for Android
// Generate a version string based on git
def computeVersionName = {
def stdout = new ByteArrayOutputStream()
exec {
commandLine 'git', 'describe', '--tags' // or commandLine 'git', 'rev-parse', 'HEAD'
standardOutput = stdout
}
return stdout.toString().trim()
}
@IanField90
IanField90 / CursorIteration.java
Last active August 29, 2015 14:18
Iterate over an Android cursor properly
// DO
if(cursor.moveToFirst()) {
do {
// do stuff with the cursor
} while (cursor.moveToNext());
}
cursor.close();
// DON'T
while (cursor.moveToNext()) {
@IanField90
IanField90 / DebugArguments.java
Created August 10, 2015 10:37
Get a logable string with parameters to an activity or fragment
public static String getJSONFromBundle(Bundle bundle) {
if (bundle == null || Build.VERSION.SDK_INT <= Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) {
return null;
}
JSONObject json = new JSONObject();
Set<String> keys = bundle.keySet();
for (String key : keys) {
try {
// json.put(key, bundle.get(key)); see edit below
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
@IanField90
IanField90 / wifi adb.md
Last active March 1, 2016 08:48
WiFi adb

Connect via usb then:

adb tcpip 5555

Disconnect

adb connect 192.168.0.17:5555 or discover by adb shell ip -f inet addr show wlan0

Resume usb mode for ADB again

adb usb

@IanField90
IanField90 / atom config addition.txt
Last active March 24, 2016 10:05
Atom configuration
runner:
extensions:
spec:
coffee: "mocha"
scopes:
coffee: "coffee"
go: "go run"
js: "node"
python: "python"
ruby: "ruby"