Skip to content

Instantly share code, notes, and snippets.

View pedrovanzella's full-sized avatar

Pedro Vanzella pedrovanzella

View GitHub Profile
version: "3.2"
services:
znc:
image: linuxserver/znc
container_name: znc
environment:
- PUID=1000
- PGID=1000
- TZ=America/Sao_Paulo
volumes:
@pedrovanzella
pedrovanzella / main.cpp
Created January 9, 2019 00:35
Q_OBJECT weirdness
#include <QApplication>
#include "window.h"
int main(int argc, char **argv)
{
QApplication app(argc, argv);
Window window;
window.show();
@pedrovanzella
pedrovanzella / extractor.py
Last active September 24, 2018 18:59
Try to unzip a file in a flat hierarchy
import zipfile
import os
from typing import List
def extract(file: str, path: str=".") -> List[str]:
names = []
with zipfile.ZipFile(file) as zip_file:
for member in zip_file.namelist():
data = zip_file.read(member)
@pedrovanzella
pedrovanzella / do-the-webp.sh
Last active September 6, 2018 14:09
Finds all cbz and cbr files in a directory and converts all files inside to webp
#!/bin/sh
# do-the-webp.sh
# Author: Pedro Vanzella <pedro@pedrovanzella.com>
# Usage: do-the-webp.sh <dir>
# License: BSD
#
# Finds all cbz and cbr files in a directory and converts all files inside to
# webp with quality 80, which should yield a 30% compression with no noticeably
# loss of quality
@pedrovanzella
pedrovanzella / application_controller.rb
Created August 27, 2018 16:39
strong params catch
class ApplicationController < ActionController::Base
#SNIP
rescue_from ActionController::UnpermittedParameters do |error|
if Rails.env.development? || Rails.env.test?
raise # Raise again and fail lowdly in dev and test
else
SLACK_NOTIFIER.ping("[#{Rails.env}] UNPERMITTED PARAMETERS! #{error}\nBacktrace:\n#{error.backtrace}")
end
end
class Memory {
public:
Memory(std::array<uint8_t, 1024> b) { buff_ = std::move(b); }
uint16_t& operator[](uint16_t addr) {
return (buff_[addr] << 8) + buff_[addr + 1]; // This doesn't work
// cannot bind non-const lvalue reference of type ‘uint16_t& {aka short unsigned int&}’ to an rvalue of type ‘uint16_t {aka short unsigned int}’
}
private:
@pedrovanzella
pedrovanzella / ops.cpp
Created February 26, 2018 13:11
operator[]
class ROM {
public:
ROM(std::array<uint8_t, 1024> buf) { _buffer = std::move(buf); }
const uint16_t operator[](const uint16_t offset) const {
if (offset > _buffer.size()) {
return 0x0;
}
// This is a big-endian machine, indexed by 16-bit words
return (_buffer[offset] << 8) + (_buffer[offset + 1]);
}
@pedrovanzella
pedrovanzella / mpi_sort.py
Last active November 22, 2017 22:24
Sort a number of random arrays using MPI
#!/usr/bin/ENV python
import numpy
from mpi4py import MPI
NUMARRAYS = 100
ARRAYSIZE = 10000
ASK_FOR_WORK_TAG = 1
WORK_TAG = 2
WORK_DONE_TAG = 3
#!/bin/sh
ffmpeg -i “$1″ -acodec alac “`basename “$1″ .flac`.m4a” \
-metadata title=\”"$(metaflac –show-tag=TITLE “$1″ | sed ‘s/title=//g’)”\” \
-metadata author=\”"$(metaflac –show-tag=ARTIST “$1″ | sed ‘s/artist=//g’)”\” \
-metadata album=\”"$(metaflac –show-tag=ALBUM “$1″ | sed ‘s/album=//g’)”\” \
-metadata year=\”"$(metaflac –show-tag=DATE “$1″ | sed ‘s/date=//g’)”\” \
-metadata track=\”"$(metaflac –show-tag=TRACKNUMBER “$1″ | sed ‘s/tracknumber=//g’)”\” \
-metadata genre=\”"$(metaflac –show-tag=GENRE “$1″ | sed ‘s/genre=//g’)”\”
;; -*- mode: emacs-lisp -*-
;; This file is loaded by Spacemacs at startup.
;; It must be stored in your home directory.
(defun dotspacemacs/layers ()
"Configuration Layers declaration.
You should not put any user code in this function besides modifying the variable
values."
(setq-default
;; Base distribution to use. This is a layer contained in the directory