Skip to content

Instantly share code, notes, and snippets.

Pedro Vanzella pedrovanzella

Block or report user

Report or block pedrovanzella

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@pedrovanzella
pedrovanzella / main.cpp
Created Jan 9, 2019
Q_OBJECT weirdness
View main.cpp
#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 Sep 24, 2018
Try to unzip a file in a flat hierarchy
View extractor.py
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)
View application_controller.rb
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
View op.cpp
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:
View ops.cpp
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 / do-the-webp.sh
Last active Sep 6, 2018
Finds all cbz and cbr files in a directory and converts all files inside to webp
View do-the-webp.sh
#!/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
View .spacemacs.el
;; -*- 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
View package.el
;;; packages.el --- rtags layer packages file for Spacemacs.
;;
;; Copyright (c) 2012-2016 Sylvain Benner & Contributors
;;
;; Author: Pedro Vanzella <pedrovanzella@Fenrir.orion>
;; URL: https://github.com/syl20bnr/spacemacs
;;
;; This file is not part of GNU Emacs.
;;
;;; License: GPLv3
View mail_controller.rb
class MailController < ApplicationController
def send(e)
begin
UserMailer.email(required_params[:to],
required_params[:from],
required_params[:template],
required_params[:content])
.deliver_now
rescue Exceptions::InvalidTemplateError
render json: {success: false,
View models.py
from microfinance import db
from passlib.hash import bcrypt
from marshmallow import Schema
from marshmallow import post_dump
class User(db.Model):
id = db.Column(db.Integer, primary_key=True)
username = db.Column(db.String(32),
You can’t perform that action at this time.