Skip to content

Instantly share code, notes, and snippets.

/*
* V4L2 video capture example
*
* This program can be used and distributed without restrictions.
*
* This program is provided with the V4L2 API
* see http://linuxtv.org/docs.php for more information
*/
#include <stdio.h>
@nhatuan84
nhatuan84 / python_decorator_guide.md
Created December 8, 2021 04:55 — forked from Zearin/python_decorator_guide.md
The best explanation of Python decorators I’ve ever seen. (An archived answer from StackOverflow.)

NOTE: This is a question I found on StackOverflow which I’ve archived here, because the answer is so effing phenomenal.


Q: How can I make a chain of function decorators in Python?


If you are not into long explanations, see [Paolo Bergantino’s answer][2].

@nhatuan84
nhatuan84 / mmap-write-locking-with-semaphore.c
Created July 7, 2021 14:40 — forked from lesovsky/mmap-write-locking-with-semaphore.c
Simple read/write on mmaped area with semaphore locks.
/*
* use -lpthread when build.
*/
#include <semaphore.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <sys/mman.h>
#include <sys/types.h>
@nhatuan84
nhatuan84 / file_response_writer.go
Created June 19, 2021 16:31 — forked from ismasan/file_response_writer.go
Write backend HTTP response to http.ResponseWriter and File
// fileResponseWriter wraps an http.ResponseWriter and a File
// passing it to an http.Handler's ServeHTTP
// will write to both the file and the response.
type fileResponseWriter struct {
file io.Writer
resp http.ResponseWriter
multi io.Writer
}
from keras.preprocessing.image import ImageDataGenerator
from keras.datasets import cifar10
import numpy as np
NUM_TO_AUGMENT=5
#load dataset
(X_train, y_train), (X_test, y_test) = cifar10.load_data()
# augumenting
print("Augmenting training set images...")
datagen = ImageDataGenerator(rotation_range=40, width_shift_range=0.2, height_shift_range=0.2, zoom_range=0.2, horizontal_flip=True, fill_mode='nearest')
#include <stdio.h>
#include <stdlib.h>
#include "platform.h"
#include "threadapi.h"
#include "crt_abstractions.h"
#include "iothub_client.h"
#include "iothub_message.h"
#include "iothubtransportamqp.h"
@nhatuan84
nhatuan84 / oled.py
Last active February 22, 2017 15:43
oled
import luma.core.serial
from luma.oled.device import sh1106
def main():
serial = i2c(port=1, address=0x3C)
device = sh1106(serial)
img_path = 'raspivn.bmp'
logo = Image.open(img_path).convert("RGBA")
fff = Image.new(logo.mode, logo.size, (255,) * 4)
import smbus
import time
I2C_ADDR = 0x27 # dung lenh sudo i2cdetect -y 1 ban se thay dia chi cua module lcd la 0x27
LCD_WIDTH = 16 # so ki tu tren 1 dong
LCD_CHR = 1 # Gui ki tu
LCD_CMD = 0 # Gui lenh
sudo apt-get install git-core
sudo apt-get update
sudo apt-get upgrade
git clone git://git.drogon.net/wiringPi
cd wiringPi
./build
cd examples