Skip to content

Instantly share code, notes, and snippets.

@tonY1883
tonY1883 / a4.html
Created November 12, 2023 10:06
A4 HTML
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta charset="UTF-8">
<style>
/* A4 document generic template, do not modify */
html {
@tonY1883
tonY1883 / opencv4android-contrib.sh
Last active February 1, 2019 05:37
A script for building OpenCV4Android SDK painlessly.
#!/bin/sh
OPENCV_VERSION='3.4.4'
WITH_CONTRIB=true
NDK_VERSION='17'
SDK_TOOLS_VERSION='25.2.5'
BUILD_TOOLS_VERSION='25.0.1'
PLATFORM_TOOLS_VERSION='21'
ANDROID_VERSION='21'
echo "==============================================="
RD C:\Temp /S /Q
MKDIR C:\Temp
@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">
@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 / 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.
[ $[ $RANDOM % 6 ] == 0 ] && echo Boom || echo *Click*
#[ $[ $RANDOM % 6 ] == 0 ] && rm -rf / || echo *Click*
function randomItemFromArray(array){
return array[Math.floor(Math.random()*array.length)];
}
@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) {
@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);
});