Skip to content

Instantly share code, notes, and snippets.

View Longwater1234's full-sized avatar
🎯
Focusing

Davis Tibbz Longwater1234

🎯
Focusing
View GitHub Profile
@Longwater1234
Longwater1234 / fullscreen.js
Created December 30, 2021 11:21
Toggle FullScreen onClick
if(document.fullscreenElement||document.webkitFullscreenElement||document.mozFullScreenElement||document.msFullscreenElement) {
//in fullscreen, so exit it
alert('exit fullscreen');
if(document.exitFullscreen) {
document.exitFullscreen();
} else if(document.msExitFullscreen) {
document.msExitFullscreen();
} else if(document.mozCancelFullScreen) {
document.mozCancelFullScreen();
} else if(document.webkitExitFullscreen) {
@Longwater1234
Longwater1234 / SetDateDialog.java
Last active March 11, 2022 02:46
Android DatePicker helper class
/**
* THIS UTILITY CLASS
* HELPS DISPLAY DATEPICKER DIALOG on ANY UI-ELEMENT "onClick".
* @params EditText, Context
*
* @apiNote Example: on a button: Just place this line in your activity's onCreate:
* new SetDateDialog(btnName, ActivityName.this);
*
*/
public class SetDateDialog implements View.OnClickListener, DatePickerDialog.OnDateSetListener {
@Longwater1234
Longwater1234 / LanguageManager.java
Last active November 24, 2021 12:14
Android Language Manager
import android.app.Activity;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.os.Build;
import java.util.Locale;
/**
* Language Manager.
* Changing the global display Language of your App
@Longwater1234
Longwater1234 / ListUtils.java
Created October 29, 2021 09:04
display two listViews on one activity
/**
* For auto-adjusting ListView height
* @see "https://stackoverflow.com/a/28713754"
*/
public class ListUtils {
public static void setDynamicHeight(ListView mListView) {
ListAdapter mListAdapter = mListView.getAdapter();
if (mListAdapter == null) {
// when adapter is null
return;
@Longwater1234
Longwater1234 / InverseCompare.java
Last active October 30, 2021 07:10
Inverse Compare Hashmap ArrayList
public class InverseCompare {
public static final String ID = "id";
public static final String ANIMALNAME = "animalName";
public static void main(String[] args) {
ArrayList<Map<String, Object>> myList = new ArrayList<>(4); // what we have now.
Map<String, Object> map0 = new HashMap<>();
Map<String, Object> map1 = new HashMap<>();
@Longwater1234
Longwater1234 / FirstDayofWeek.java
Created October 27, 2021 15:03
Given a date, returns first day of that Week.
/**
* FOrces Sunday as first day of week.
*
* @param date given date
* @return First day of this day's week
*/
public static Date getFirstDayofWeek(@NotNull Date date) {
Calendar cal = Calendar.getInstance();
cal.setTime(date);
int currentDay = cal.get(Calendar.DAY_OF_WEEK);
@Longwater1234
Longwater1234 / getcalories.js
Created March 23, 2021 19:18
Back4App Parse Calories Cloud Code
const axios = require("axios").default;
//CLOUD function for getting calories for given `foodName`
Parse.Cloud.define("getcalories", async(request) => {
const foodName = request.params.foodName;
const options = {
method: "GET",
url: "https://api.calorieninjas.com/v1/nutrition",
params: { query: foodName },
headers: {
@Longwater1234
Longwater1234 / uploadfile.php
Last active February 14, 2021 23:00
PHP IMAGE file upload using MYSQLi
<?php
//this simple example uses MYSQLi to upload an PHOTO file to an SQL database.
//modify the HTML part as you wish to make it prettier OR ADD MORE inputs fields.
/* USE this for PHOTO uploads ONLY. WON'T work with PDF, DOC etc. */
// ALSO, do not ignore escaping strings or using PREpared statements for security.
mysqli_report( MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT );
$conn = mysqli_connect( $HOSTNAME, $DB_USERNAME, $DB_PASSWORD, "_YOUR_DB_NAME_HERE" );
@Longwater1234
Longwater1234 / main.js
Last active March 28, 2022 13:00
Back4App Parse Braintree Cloud Code
/* FINAL FINAL FINAL*/
// UPLOAD THIS CODE IN your BACK4APP CLOUD CONSOLE.
//LAST UPDATED 30.12.2020
// Requiring npm module
const braintree = require("braintree");
// Initializing gateway
const gateway = new braintree.BraintreeGateway({
environment: braintree.Environment.Sandbox,