Skip to content

Instantly share code, notes, and snippets.

View alhazmy13's full-sized avatar
👽
keep calm and work hard

Abdullah Alhazmy alhazmy13

👽
keep calm and work hard
View GitHub Profile
@alhazmy13
alhazmy13 / Android.gitignore
Created February 21, 2016 08:04
.gitignore for Android
# Built application files
*.apk
*.ap_
# Files for the Dalvik VM
*.dex
# Java class files
*.class
@alhazmy13
alhazmy13 / Binary & String converter
Last active March 15, 2016 11:29
Binary & String converter
//==============================================================
// Binary To String
//==============================================================
public static String int2str( String s ) {
String[] ss = s.split( " " );
StringBuilder sb = new StringBuilder();
for ( int i = 0; i < ss.length; i++ ) {
sb.append( Character.toString((char)Long.parseLong( ss[i], 2 ) ));
}
return sb.toString();
@alhazmy13
alhazmy13 / RealmMigratio
Last active March 15, 2016 11:30
RealmMigration must be provided
If you don't have any problem in loosing your old data then you can delete Realm Configuration and create new one.
-------------------------------------------------------------------------------
Realm realm = null;
try {
realm = Realm.getInstance(MainActivity.this);
} catch (RealmMigrationNeededException r) {
Realm.deleteRealmFile(MainActivity.this);
realm = Realm.getInstance(MainActivity.this);
}
-------------------------------------------------------------------------------
@alhazmy13
alhazmy13 / Realm auto-increment
Last active March 24, 2016 10:34
Realm auto-increment
public int getNextID() {
return mRealm.allObjects(YOUR_CLASS).size() > 0 ? realm.where(YOUR_CLASS).max("id").intValue() + 1 : 0;
}
@alhazmy13
alhazmy13 / Checkstyle.md
Last active June 6, 2016 12:30
Improve quality and syntax of your Android code

Checkstyle is a development tool to help programmers write Java code that adheres to a coding standard. It automates the process of checking Java code to spare humans of this boring (but important) task.

Add below code to your project and then launch the task checkstyle from the gradle panel alt text

/**
* Created by Alhazmy13 on 7/11/16.
*/
public class Test {
int arg1,arg2,arg3;
public Test() {
// A no arguments constructor that sends default values to the largest
this(1,2,3);
@alhazmy13
alhazmy13 / temp.md
Last active July 24, 2016 06:30
Run PHP script in background
  • Create a daemon configuration script under /etc/init ( NOT /etc/init.d ):-

nano /etc/init/mybot.conf

code sample:

description "MyBot Daemon"
author "alhazmy13"
start on startup
stop on shutdown
// Create a RealmConfiguration that saves the Realm file in the app's "files" directory.
RealmConfiguration realmConfig = new RealmConfiguration.Builder(context).build();
Realm.setDefaultConfiguration(realmConfig);
// Get a Realm instance for this thread
Realm realm = Realm.getDefaultInstance();
@alhazmy13
alhazmy13 / App.java
Last active November 18, 2016 00:38
Dagger example with App & Net Module
public class App extends Application {
private static final String TAG = "App";
private NetComponent mNetComponent;
@Override
public void onCreate() {
super.onCreate();
mNetComponent = DaggerNetComponent.builder()
.appModule(new AppModule(this)) // This also corresponds to the name of your module: %component_name%Module
.netModule(new NetModule(UrlHelper.getBaseUrl()))
@alhazmy13
alhazmy13 / LocalUtility.java
Last active March 1, 2017 05:18
This class is used to change your application locale and save this change for the next time.
/**
* Created by Alhazmy13 on 11/6/16.
*/
public class LocalUtility {
private static final String SAVED_LANG = "LOCALE_SAVED_LANG";
public static void onCreate(Context context) {
String lang = getSavedData(context, Locale.getDefault().getLanguage());
setLocale(context, lang);