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
rarakat / getPublicIP.py
Last active Sep 8, 2016
[Python] Get Public IP and upload it to your DropBox account
View getPublicIP.py
#!/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
rarakat / BaasQuery.java
Created Dec 10, 2015
[Java/Android] BaasBox - BaasQuery, fetchAll and store result in List<BaasDocument>
View BaasQuery.java
// 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
rarakat / DeleteFile.java
Created Dec 10, 2015
[Java/Android] BaasBox - Delete a File
View DeleteFile.java
BaasFile oldFile = new BaasFile();
// Fetch the file from server
oldFile.fetch(oldFileID, new BaasHandler<BaasFile>() {
@Override
public void handle(BaasResult<BaasFile> baasResult) { // Successfully fetch file
if (baasResult.isSuccess()) {
Log.d(TAG, "Received old file");
// Delete the file from server
@rarakat
rarakat / convertBitmapToByteArray.java
Created Dec 10, 2015
[Java/Android] Convert Bitmap/Image to Byte Array
View convertBitmapToByteArray.java
public static byte[] convertBitmapToByteArray(Bitmap bitmap){
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
return stream.toByteArray();
}
@rarakat
rarakat / scaleBitmapAndKeepRation.java
Created Dec 10, 2015
[Java/Android] Scale Bitmap/Image and Keep Aspect Ratio
View scaleBitmapAndKeepRation.java
//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;
}
else
@rarakat
rarakat / 1ResizeAndUploadImageBaasFile.java
Last active Dec 10, 2015
[Java/Android] BaasBox - Resize and Upload an Image file in byteArray to BaasBox
View 1ResizeAndUploadImageBaasFile.java
// 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),
720,
720);
byte[] byteArray = convertBitmapToByteArray(bitmap);
@rarakat
rarakat / CreateDocument.java
Created Dec 10, 2015
[Java/Android] BaasBox - Save a document and Grant.READ to all registered user
View CreateDocument.java
// 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
doc.save(new BaasHandler<BaasDocument>() {
@rarakat
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="http://schemas.android.com/apk/res/android"
package="com.example.app">
<!-- Permisssion for internet -->
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:name="com.example.app.MyApplication"
android:allowBackup="true"
@rarakat
rarakat / AlertDialogOk.java
Created Dec 10, 2015
[Java/Android] AlertDialog
View AlertDialogOk.java
// 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,
doYourThing();
}
});
@rarakat
rarakat / main.cpp
Created Dec 10, 2015
[C++] Simple XOR Encryption
View main.cpp
// A simple c++ program to
// illustrate basic encryption
// and decryption
#include<iostream>
using namespace std;
void encrypt(char *);
void decrypt(char *);
You can’t perform that action at this time.