Skip to content

Instantly share code, notes, and snippets.

View fernandocyder's full-sized avatar

Fernando Karnagi fernandocyder

View GitHub Profile
@fernandocyder
fernandocyder / Dockerfile
Created May 5, 2021 01:35 — forked from bsod90/Dockerfile
Centos 7 with Systemd Dockerfile
FROM centos:7
MAINTAINER "orion" <[email protected]>
# Steps needed to use systemd enabled docker containers.
# Reference: https://hub.docker.com/_/centos/
ENV container docker
RUN (cd /lib/systemd/system/sysinit.target.wants/; for i in *; do [ $i == \
systemd-tmpfiles-setup.service ] || rm -f $i; done); \
rm -f /lib/systemd/system/multi-user.target.wants/*;\
rm -f /etc/systemd/system/*.wants/*;\
@fernandocyder
fernandocyder / harden.sh
Created April 6, 2021 14:07 — forked from jumanjiman/harden.sh
hardening script for an alpine docker container
#!/bin/sh
# Copyright 2020 Paul Morgan
# License: GPLv2 (https://www.gnu.org/licenses/old-licenses/gpl-2.0.en.html)
set -x
set -e
#
# Docker build calls this script to harden the image during build.
#
# NOTE: To build on CircleCI, you must take care to keep the `find`
# command out of the /proc filesystem to avoid errors like:
<div className="qrCode">
<video
style={{
maxWidth: 175,
margin: "auto",
}}
onPlaying={e => {
setCameraPlaying(true);
}} id="video" playsInline autoPlay></video>
public class BoofCVQRCodeReader {
public static String read(String filePath) {
// read the image to memory
BufferedImage input = UtilImageIO.loadImage(filePath);
// gray-out the image, easy to process
GrayU8 gray = ConvertBufferedImage.convertFrom(input, (GrayU8) null);
QrCodeDetector<GrayU8> detector = FactoryFiducial.qrcode(null, GrayU8.class);
@PostMapping(path = "/upload", produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<QRTextResponseEntity> singleFileUpload(@RequestParam("qr_base64") MultipartFile file,
RedirectAttributes redirectAttributes) {
// there has to be a valid file
if (file.isEmpty()) {
redirectAttributes.addFlashAttribute("message", "Please select a file to upload");
throw new ResponseStatusException(
HttpStatus.BAD_REQUEST, "file not valid"
);
const uploadToServer = async (base64Str) => {
// prepare the base64 image
// const base64 = 'data:image/png;base64,' + base64Str;
// convert base64 to post body blob
const blob = await fetch(base64Str).then(res => res.blob());
const formData = new FormData();
formData.append('qr_base64', blob, 'qr_code.png');
const checkQrCode = () => {
window.imageCapture.grabFrame()
.then(imageBitmap => {
const imageBase64 = imgToBase64(imageBitmap);
console.log("get image bitmap and uploading to server");
uploadToServer(imageBase64);
})
.catch(error => {
console.log("error during image capture: ", error)
});
const gotStream = (stream) => {
window.stream = stream; // make stream available to console
window.imageCapture = new ImageCapture(stream.getTracks()[0]);
console.log(window.imageCapture)
const videoElement = document.querySelector('video');
videoElement.srcObject = stream;
setInterval(checkQrCode, 5000);
const start = async (camId) => {
// stop the currently running video
stopVideo();
// use the rear camera, if any, else any camera
const constraints = {
video: { deviceId: camId ? { exact: camId } : undefined }
};
// get medias and further process
const initialiseCamera = async () => {
try {
let cam1 = null; // stores running rear camera ID
let cam2 = null; // stores running default camera ID
const devices = await navigator.mediaDevices.enumerateDevices();
// labels of rear camera, detected by popular mobile devices
const rearCameraLabels = ['rear', 'back', 'environment'];