Skip to content

Instantly share code, notes, and snippets.

@tonY1883
tonY1883 / snackbar_indefinite.java
Last active May 14, 2017 08:19
code for displaying dismissable snackbar in android
public static void showIndefiniteSnackBar(View view, String message){
final Snackbar snack = Snackbar.make(view, message, Snackbar.LENGTH_INDEFINITE);
snack.setAction(android.R.string.ok, new View.OnClickListener() {
@Override
public void onClick(View view) {
snack.dismiss();
}
});
snack.show();
@tonY1883
tonY1883 / SQLiteHelper.java
Created July 30, 2017 06:53
Android SQLiteHelper with auto upgrade and downgrade
private class SQLiteHelper extends SQLiteOpenHelper {
public DatabaseOperations(Context context) {
super(context, DatabaseSchemas.DATABASE_NAME, null, DatabaseSchemas.DATABASE_VERSION);
}
public void onCreate(SQLiteDatabase db) {
//Create all tables
db.execSQL(DatabaseSchemas.Table.CREATION_SQL);
}
.floating {
animation-name: floating;
animation-duration: 4s;
animation-iteration-count: infinite;
animation-timing-function: ease-in-out;
margin-left: 30px;
margin-top: 5px;
}
@keyframes floating {
@tonY1883
tonY1883 / saveFile.js
Created July 31, 2017 09:13
save a text file with js
function saveFile(text, filename, mime) {
var link = document.createElement('a');
link.setAttribute('download', filename);
link.href = window.URL.createObjectURL(new Blob([text], {type: mime}));
document.body.appendChild(link);
window.requestAnimationFrame(function () {
var event = new MouseEvent('click');
link.dispatchEvent(event);
document.body.removeChild(link);
});
@tonY1883
tonY1883 / loadFile.js
Created August 7, 2017 08:10
open a local file with js
function loadFile(type) {
var fileSelector = $('<input type="file">');
if (type) {
fileSelector.attr('accept', type);
}
fileSelector.change(function () {
var file = fileSelector[0].files[0];
fname = file.name;
var reader = new FileReader();
reader.onload = function (e) {
function randomItemFromArray(array){
return array[Math.floor(Math.random()*array.length)];
}
[ $[ $RANDOM % 6 ] == 0 ] && echo Boom || echo *Click*
#[ $[ $RANDOM % 6 ] == 0 ] && rm -rf / || echo *Click*
@tonY1883
tonY1883 / mass_jpg2pdf.sh
Created March 4, 2018 08:05
Script to convert a folder of jpgs into a single pdf
#!/bin/bash
echo "* * * * * * * *"
echo "* .JPG to .PDF File Converting Utility *"
echo "* By tonY1883@GitHub *"
echo "* * * * * * * *"
sleep 1
read -p "Please input the name of the folder:" -e input
sleep 1
echo "Reading folder..."
sleep 1
@tonY1883
tonY1883 / dialog_picker.xml
Last active May 14, 2018 07:22
Android number picker dialog
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="4dp"
android:layout_marginLeft="4dp"
android:layout_marginRight="4dp"
android:layout_marginTop="16dp"
android:orientation="vertical">
RD C:\Temp /S /Q
MKDIR C:\Temp