Skip to content

Instantly share code, notes, and snippets.

View jesustorresdev's full-sized avatar

Jesús Torres jesustorresdev

View GitHub Profile
@jesustorresdev
jesustorresdev / main.cpp
Created March 28, 2016 16:20
Ejemplo de pool de hilos en C++
#include <iostream>
#include <condition_variable>
#include <mutex>
#include <queue>
#include <thread>
#include <memory>
#include <vector>
#include "unistd.h"
@jesustorresdev
jesustorresdev / smartmontools-run.d-notify
Last active November 8, 2016 19:09
Smartmontools visual notification script for desktop environments
#!/bin/bash -e
#
# smartmontools-run.d-notify - Smartmontools visual notification script for desktop environments
#
# https://gist.github.com/aplatanado/1331876d6e1547aeb9b2d02861e9ae92
#
# Requires notify-send-all:
# https://gist.github.com/aplatanado/e8810dbceece820b4ae5aa0ee5ca200
#
@jesustorresdev
jesustorresdev / snapraid
Last active November 8, 2016 20:34
Script for nightly SnapRAID syncs and scrubs by @rubylaser (http://zackreed.me/updated-snapraid-sync-script/)
# /etc/cron.d/snapraid: crontab entries for snapraid package
# Run a SnapRAID diff and then sync
30 23 * * * root /usr/local/sbin/snapraid_diff_n_sync.sh
@jesustorresdev
jesustorresdev / notify-send-all
Last active May 19, 2024 17:19
Script for the root to send desktop notifications to all active sessions
#!/bin/bash
#
# notify-send-all - Script to send desktop notifications to all active sessions
#
# https://gist.github.com/aplatanado/e8810dbceece820b4ae5aa0ee5ca200a
#
### Utility functions
# A few utility functions to show errors, handle programa exit and more
class MyThread : public QThread
{
Q_OBJECT
protected:
void run();
};
void MyThread::run()
{
class FiniteBuffer : public QObject
{
Q_OBJECT
public:
FiniteBuffer(int size);
~FiniteBuffer();
// Métodos de inserción y extracción para el productor y el
// consumidor, respectivamente.
void MyWindow::on_video_updated(const QRect& rect)
{
finiteBuffer_->insertFrame(movie_->currentImage());
}
void FiniteBuffer::insertFrame(const QImage& frame)
{
// Bloquear el cerrojo. Es lo mismo que hacer manualmente:
// mutex_.lock()
QMutexLocker lock(&mutex);
// El código del productor a partir de este punto no se
// ejecutará si el consumidor ha bloqueado el cerrojo
// primero.
class FrameProcessingThread : public QThread
{
Q_OBJECT
public:
FrameProcessingThread(FiniteBuffer* buffer,
QObject *parent = 0)
: QThread(parent), buffer_(buffer)
{}
QImage FiniteBuffer::extractFrame()
{
// Bloquear el cerrojo. Es lo mismo que hacer manualmente:
// mutex_.lock()
QMutexLocker lock(&mutex);
// El código del productor a partir de este punto no se
// ejecutará si el productor ha bloqueado el cerrojo
// primero.