Skip to content

Instantly share code, notes, and snippets.

View solominh's full-sized avatar

Minh Tran solominh

View GitHub Profile
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="false"
android:color="@color/flat_disabled_text"/>
<item android:color="@color/flat_normal_text"/>
</selector>
@solominh
solominh / MediaPlayer-excerpt.java
Created March 23, 2016 05:23 — forked from jonjensen/MediaPlayer-excerpt.java
simplified example of Android sound player
/**
* Convenience method to create a MediaPlayer for a given resource id.
* On success, {@link #prepare()} will already have been called and must not be called again.
* <p>When done with the MediaPlayer, you should call {@link #release()},
* to free the resources. If not released, too many MediaPlayer instances will
* result in an exception.</p>
*
* @param context the Context to use
* @param resid the raw resource id (<var>R.raw.&lt;something></var>) for
* the resource to use as the datasource
@solominh
solominh / Log.java
Created May 16, 2016 07:00
Android Log Class
/*
* Copyright (C) 2006 The Android Open Source Project
*
* 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
class Employee {
constructor(name) {
this._name = name;
}
doWork() {
console.log(`${this._name} is working`);
}
let a = [1, 2, 3, 4, 5]
for (let v of a) {
if (v == 3) {
a.splice(0, 2); // remove 2 element from index 0
a = undefined; // for..of will have arrayname =a => undefined assignment will not affect for..of
}
console.log(v);
}
console.log(a) // undefined
function copy(obj) {
var copy = Object.create(Object.getPrototypeOf(obj));
var propNames = Object.getOwnPropertyNames(obj);
propNames.forEach(function (name) {
var desc = Object.getOwnPropertyDescriptor(obj, name);
Object.defineProperty(copy, name, desc);
});
return copy;
class Person {
constructor(name) {
this.name = name;
}
static realStaticMethod() {
console.log('static method');
}
}
function Person(name) {
this.name = name;
}
Person.prototype.staticProperty = 10;
var john = new Person('john');
console.log(john.staticProperty); // 10
john.staticProperty = 5;
console.log(Person.staticProperty) // 10
class Person():
static_property = 10
def __init__(self, name):
self.name = name
john = Person('john')
print(john.static_property) # 10 => find in prototype
john.static_property = 5 # Create new own property
public class StaticProperty {
public static class Person {
static int staticProperty = 10;
String name;
public Person(String name) {
this.name = name;
}