Skip to content

Instantly share code, notes, and snippets.

★☆★☆★☆★☆★☆ rarakat

  • Singapore
Block or report user

Report or block rarakat

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
rarakat /
Last active Sep 8, 2016
[Python] Get Public IP and upload it to your DropBox account
#!/usr/bin/env python
# Useful if hosting something through a dynamic IP address
import dropbox
import urllib
import re
from datetime import datetime
from time import sleep
rarakat /
Created Dec 10, 2015
[Java/Android] BaasBox - BaasQuery, fetchAll and store result in List<BaasDocument>
// What to retrive?
// All the Documents in the 'note' Collection
// WHERE Document _author is the current logged in user
// ORDERBY _creation_date descending
// List to hold the notes
List<BaasDocument> noteList = new ArrayList<BaasDocument>();
// using pagination and selection
rarakat /
Created Dec 10, 2015
[Java/Android] BaasBox - Delete a File
BaasFile oldFile = new BaasFile();
// Fetch the file from server
oldFile.fetch(oldFileID, new BaasHandler<BaasFile>() {
public void handle(BaasResult<BaasFile> baasResult) { // Successfully fetch file
if (baasResult.isSuccess()) {
Log.d(TAG, "Received old file");
// Delete the file from server
rarakat /
Created Dec 10, 2015
[Java/Android] Convert Bitmap/Image to Byte Array
public static byte[] convertBitmapToByteArray(Bitmap bitmap){
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
return stream.toByteArray();
rarakat /
Created Dec 10, 2015
[Java/Android] Scale Bitmap/Image and Keep Aspect Ratio
//rescale image
public static Bitmap scaleBitmapAndKeepRation(Bitmap TargetBmp,int reqHeightInPixels,int reqWidthInPixels)
if(TargetBmp.getWidth() >= reqHeightInPixels && TargetBmp.getHeight() >= reqHeightInPixels) {
Matrix m = new Matrix();
m.setRectToRect(new RectF(0, 0, TargetBmp.getWidth(), TargetBmp.getHeight()), new RectF(0, 0, reqWidthInPixels, reqHeightInPixels), Matrix.ScaleToFit.CENTER);
Bitmap scaledBitmap = Bitmap.createBitmap(TargetBmp, 0, 0, TargetBmp.getWidth(), TargetBmp.getHeight(), m, true);
return scaledBitmap;
rarakat /
Last active Dec 10, 2015
[Java/Android] BaasBox - Resize and Upload an Image file in byteArray to BaasBox
// Resize and Upload a Image file in byteArray to BaasBox
// try catch for null and IO exception.
try {
// Convert bitmap to byteArray
Bitmap bitmap = scaleBitmapAndKeepRation(
MediaStore.Images.Media.getBitmap(getApplicationContext().getContentResolver(), selectedImageUri),
byte[] byteArray = convertBitmapToByteArray(bitmap);
rarakat /
Created Dec 10, 2015
[Java/Android] BaasBox - Save a document and Grant.READ to all registered user
// Create a document in the "note" Collection
// Only Admin can create Collection
// Create and putString to the document
BaasDocument doc = new BaasDocument("note");
doc.put("title", "How to Sleep?")
.put("content", "Get a bed and then go to sleep.");
// Save the document and grant read to all registered user BaasHandler<BaasDocument>() {
rarakat / AndroidManifest.xml
Created Dec 10, 2015
[Java/Android] BaasBox (Starting of Application)
View AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android=""
<!-- Permisssion for internet -->
<uses-permission android:name="android.permission.INTERNET"/>
rarakat /
Created Dec 10, 2015
[Java/Android] AlertDialog
// An alert dialog with OK button,
AlertDialog.Builder alert = new AlertDialog.Builder(getApplicationContext());
alert.setTitle("Your Title");
alert.setMessage("Your message goes here");
alert.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// When the user click ok,
rarakat / main.cpp
Created Dec 10, 2015
[C++] Simple XOR Encryption
View main.cpp
// A simple c++ program to
// illustrate basic encryption
// and decryption
using namespace std;
void encrypt(char *);
void decrypt(char *);
You can’t perform that action at this time.