Skip to content

Instantly share code, notes, and snippets.

@dwburke
dwburke / unmarshal.defaults.go
Created June 29, 2020 15:55
Default values when unmarshalling json in go
package foo
type Foo struct {
Field string `json:"field"`
}
// UnmarshalJSON is the implementation of the json.Unmarshaler interface.
func (t *Foo) UnmarshalJSON(data []byte) error {
type innerFoo Foo
inner := &innerFoo{
@maghoff
maghoff / escape-bitbucket.sh
Last active April 25, 2021 18:36
Migrate all your repos (including wikis, _excluding_ issues) from Bitbucket to GitHub, converting hg to git in the process
#!/usr/bin/env bash
# Originally published on https://magnushoff.com/blog/kick-the-bitbucket/
# Copyright (c) 2019 Magnus Hovland Hoff
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
@crearo
crearo / fragment_shader_NV12_to_RGB.frag
Last active August 1, 2024 01:57
A fragment shader to convert NV12 to RGB.
/** A fragment shader to convert NV12 to RGB.
* Input textures Y - is a block of size w*h.
* texture UV is of size w*h/2.
* Remember, both U and V are individually of size w/2*h/2, but they are interleaved.
* The layout looks like this :
* ----------
* | |
* | Y | size = w*h
* | |
* |________|
@sdumetz
sdumetz / Encoder.hpp
Created May 19, 2017 14:44
barebone C++ MPEG4/h264 video encoder using libavformat and libavcodec. Options choice is explained in https://sdumetz.github.io/2017/05/19/libav-encoding-for-ios.html
#include <stdio.h>
#include <iostream>
extern "C"{
#include <libavformat/avformat.h>
#include <libavformat/avio.h>
#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
#include <libavutil/imgutils.h> //for av_image_alloc only
#include <libavutil/opt.h>
@irbull
irbull / OpenSSLExample.cpp
Created August 11, 2016 18:32
Code signing and verification with OpenSSL
#include <iostream>
#include <openssl/aes.h>
#include <openssl/evp.h>
#include <openssl/rsa.h>
#include <openssl/pem.h>
#include <openssl/ssl.h>
#include <openssl/bio.h>
#include <openssl/err.h>
#include <assert.h>
@Redchards
Redchards / Bind.cxx
Last active December 5, 2023 13:54
Simple implementation of a function like std::bind.
#include <iostream>
#include <functional>
#include <tuple>
#include <type_traits>
// Actually, a subtle bug may arise when the function is using index_constant as parameter.
// For this reason, a more correct implementation should define a specialized class, hidden in a namespace,
// and forbid the use in other places.
// An easier, more correct, but more verbose way would be to just define two different classes for the argument list
// and the bounded arguments, to avoid the confusion with the index_constant bracket operator overload.
@pokle
pokle / Dockerfile
Created April 16, 2014 04:45
Run ssh server inside a Centos/Redhat Docker container
# ssh server
# Don't forget to run '/usr/sbin/sshd -D' if you actually want to ssh into this container
RUN yum install -y openssh-server
RUN ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key -N ''
RUN ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key -N ''
ADD src/sshd/sshd_config /etc/ssh/sshd_config
RUN echo root:welcome1 | chpasswd
@royshil
royshil / gist:6318407
Created August 23, 2013 11:39
A CMake Find module for FFMPEG that will tear the HD apart looking for the libs and includes ;)
# - Try to find FFMPEG
# Once done this will define
# FFMPEG_FOUND - System has FFMPEG
# FFMPEG_INCLUDE_DIRS - The FFMPEG include directories
# FFMPEG_LIBRARIES - The libraries needed to use FFMPEG
# FFMPEG_LIBRARY_DIRS - The directory to find FFMPEG libraries
#
# written by Roy Shilkrot 2013 http://www.morethantechnical.com/
#
@thearn
thearn / svd_approximate.py
Last active January 8, 2024 20:25
Function to generate an SVD low-rank approximation of a matrix, using numpy.linalg.svd. Can be used as a form of compression, or to reduce the condition number of a matrix.
import numpy as np
def low_rank_approx(SVD=None, A=None, r=1):
"""
Computes an r-rank approximation of a matrix
given the component u, s, and v of it's SVD
Requires: numpy
"""