Skip to content

Instantly share code, notes, and snippets.

👽
keep calm and work hard

Abdullah Alhazmy alhazmy13

👽
keep calm and work hard
Block or report user

Report or block alhazmy13

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@alhazmy13
alhazmy13 / Android.gitignore
Created Feb 21, 2016
.gitignore for Android
View Android.gitignore
# Built application files
*.apk
*.ap_
# Files for the Dalvik VM
*.dex
# Java class files
*.class
View OpenPDF file - Android
1. create assets folder in src under your app name.
2. In this assets folder keep your pdf files e.g. file.pdf.
3 now come your activity i.e MainActivity.java
4. setListener on any UI component what you want i.e (Button,ImageView,ImageButton);
5. In this listener call one user defined method i.e. openPDFFiles("file.pdf");
the openPDFFiles() method have below code:—-
private void openPDFFiles(String fileName) //fileName is the pdf file name which is keep in assets folder. ex file.pdf
{
@alhazmy13
alhazmy13 / RealmMigratio
Last active Mar 15, 2016
RealmMigration must be provided
View RealmMigratio
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 Mar 24, 2016
Realm auto-increment
View Realm auto-increment
public int getNextID() {
return mRealm.allObjects(YOUR_CLASS).size() > 0 ? realm.where(YOUR_CLASS).max("id").intValue() + 1 : 0;
}
@alhazmy13
alhazmy13 / Binary & String converter
Last active Mar 15, 2016
Binary & String converter
View 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 / Example.java
Last active May 9, 2016
RxJava and Retrofit - Example with Github API
View Example.java
package com.company;
import retrofit.RestAdapter;
import retrofit.http.GET;
import retrofit.http.Path;
import rx.Observable;
import rx.Subscriber;
import rx.functions.Action1;
import rx.functions.Func1;
import rx.functions.Func2;
@alhazmy13
alhazmy13 / Checkstyle.md
Last active Jun 6, 2016
Improve quality and syntax of your Android code
View Checkstyle.md

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

View Test.java
/**
* 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);
View Relam.java
// 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 / temp.md
Last active Jul 24, 2016
Run PHP script in background
View temp.md
  • 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
You can’t perform that action at this time.