Skip to content

Instantly share code, notes, and snippets.

@tonY1883
tonY1883 / center.css
Last active February 20, 2019 08:15
CSS code for elements to sit right in the center of the page.
.center {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
text-align: center;
min-height: 100vh;
}
@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 / ValidateYoutubeVideoId.js
Created September 14, 2017 02:18
A small trick to check if youtube video exist with its id.
function validVideoId(id) {
var img = new Image();
img.src = "http://img.youtube.com/vi/" + id + "/mqdefault.jpg";
img.onload = function () {
checkThumbnail(this.width);
}
}
function checkThumbnail(width) {
//HACK a mq thumbnail has width of 320.
@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