Skip to content

Instantly share code, notes, and snippets.

View akuafif's full-sized avatar

akuafif akuafif

View GitHub Profile
@akuafif
akuafif / sortDescArray.js
Last active July 15, 2023 15:33
sortDescArray.js
// Sort Descending Date
tempArray = originalArray.slice();
tempArray.sort(function(a,b){
return new Date(b.date) - new Date(a.date);
});
for (i = 0; i < tempArray.length; i++) {
console.log(`\t${i + 1}) ${tempArray[i].date} - ${tempArray[i].displayName}`);
}
@akuafif
akuafif / ict162_toa_class_generator.py
Created January 22, 2022 11:05
ICT162 Class Generator. To save time during the TOA exam.
# class builder to save time during 162 toa exam
# no gui validation
import tkinter as tk
from tkinter import Frame, Button, Label, StringVar, messagebox
from tkinter.scrolledtext import ScrolledText
from tkinter.constants import DISABLED, NORMAL, END, WORD
class ClassBuilder(Frame):
""" ClassBuilder is a subclass of Frame class """
@akuafif
akuafif / bitwise_calc.py
Created November 14, 2021 07:18
Perform AND OR XOR bitwise operation
def valid_expression(expression: str) -> bool:
""" Returns True if string is valid binary expression. False otherwise.
- Operand is valid binary digits
- Operator is either '!', '&', or '|'
- Length of operands is more than 2 digits
- Both operands are same length
- Expression is in the format of “operand operator operand”, seperated by blanks"""
if len(expression.split()) == 3:
first, operator, second = expression.split()
@akuafif
akuafif / ahref_call_vb_sub.hta
Created September 25, 2021 10:56
[HTA/VBScript] Using a herf to call vb sub
<html>
<head>
<title>HTA a href sub calling</title>
<HTA:APPLICATION
APPLICATIONNAME="HTA a href sub calling"
ID="hta_utility"
border = "thin"
borderStyle = "tool"
caption = "yes"
contextMenu = "yes"
@akuafif
akuafif / getPublicIP.py
Last active September 8, 2016 19:36
[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
@akuafif
akuafif / BaasQuery.java
Created December 10, 2015 22:15
[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
@akuafif
akuafif / DeleteFile.java
Created December 10, 2015 21:59
[Java/Android] BaasBox - Delete a File
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
@akuafif
akuafif / convertBitmapToByteArray.java
Created December 10, 2015 21:55
[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();
}
@akuafif
akuafif / scaleBitmapAndKeepRation.java
Created December 10, 2015 21:54
[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;
}
else
@akuafif
akuafif / 1ResizeAndUploadImageBaasFile.java
Last active December 10, 2015 22:03
[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),
720,
720);
byte[] byteArray = convertBitmapToByteArray(bitmap);