Skip to content

Instantly share code, notes, and snippets.

@endavid
endavid / resources.cpp
Created January 22, 2016 13:22
OpenGL ES 1.0 Create framebuffer textures example from Snake on a Sphere
PushRenderBuffer();
PushFrameBuffer();
// Create the renderbuffers and framebuffers
glGenRenderbuffers(ResourceSky::NUM_BUFFERS, g_res->renderBuffer);
glGenFramebuffers(ResourceSky::NUM_BUFFERS, g_res->frameBuffer);
for (int i = 0; i < ResourceSky::NUM_BUFFERS; ++i) {
glBindRenderbuffer(GL_RENDERBUFFER, g_res->renderBuffer[i]);
glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8_OES, g_res->width[i], g_res->height[i]);
@endavid
endavid / my.bashrc
Last active March 24, 2017 17:54
Remove git merged branches with prompt for every remote branch
function rmb {
current_branch=$(git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/')
if [ "$current_branch" != "master" ]; then
echo "WARNING: You are on branch $current_branch, NOT master."
fi
echo "Pruning branches no longer on origin..."
git remote prune origin
echo "Fetching merged branches..."
remote_branches=$(git branch -r --merged | grep -v '/master$' | grep -v "/$current_branch$")
local_branches=$(git branch --merged | grep -v 'master$' | grep -v "$current_branch$")
@endavid
endavid / my.bashrc
Last active July 28, 2017 15:29
Remove closed mercurial branches from git
# pass --simulate to avoid actual deletion
# pass --donotprompt to delete without prompting
function rmbHgClosed() {
option=$1
current_branch=$(git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/')
if [ "$current_branch" != "master" ]; then
echo "WARNING: You are on branch $current_branch, NOT master."
fi
echo "Fetching remote branches..."
remote_branches=$(git branch -r | grep -v '/master$' | grep -v "/$current_branch$")
@endavid
endavid / scaleiMovieiPhoneXAppPreview.sh
Created December 29, 2017 00:09
Crop & scale iPhoneX video from iMovie for App Preview
# Still undocumented here https://developer.apple.com/support/app-previews/
# or here https://developer.apple.com/library/content/documentation/LanguagesUtilities/Conceptual/iTunesConnect_Guide/Chapters/Properties.html
# but iPhoneX App Previews required size is 886x1920
# Unfortunately, iMovie seems to be dumb and creates a 750x1334 App Preview video from your iPhoneX capture
# -- and with black margins on the side
# So you need to crop & scale the video up before you submit it to iTunesConnect:
ffmpeg -i iPhoneX-iMovie.mp4 -filter:v "crop=616:1334:68:0" -c:a copy cropped.mp4
ffmpeg -i cropped.mp4 -vf scale=886:1920 -c:a copy iPhoneX-final.mp4
@endavid
endavid / multiple.cpp
Created October 8, 2019 08:43
Multiple inheritance -- how to rename a method of an implemented interface
// g++ -Wall -o multiple multiple.cpp
#include <iostream>
// Based on this answer:
// https://stackoverflow.com/a/2005142
// I renamed methods for a serialization example.
// In this example, there's a "Unicorn" class that knows how to doA and doB,
// but user of the respective interfaces do not expect B to get serialized
// when they try to serialize A.
@endavid
endavid / s3move.sh
Last active December 3, 2019 11:12
#AWS script to move a range of files from an #S3 bucket
#!/bin/bash
# e.g.
# ./s3move.sh -d Images/all/ "15-36-58" "15-54-27" Captures/iPhone6/
DEBUG=
BUCKET=screenshots
PREFIX=Screenshot_
EXT=".png"
while getopts ":db:p:e:" opt; do
@endavid
endavid / enum-example.swift
Created February 25, 2020 14:07
#swift enum example for #medium
enum SerializationError: Error {
case missing(String)
case invalid(String, Any)
}
// in some deserialization code
// ...
guard let vertexData = json["vertices"] as? [NSNumber] else {
throw SerializationError.missing("vertices")
}
@endavid
endavid / triple-equalities.swift
Created February 26, 2020 17:58
#swift triple equality examples for #medium
struct Bread {
let rating : Int
}
class Cheese {
let rating : Int
init(rating: Int) {
self.rating = rating
}
}
var c1 = Cheese(rating: 0)
@endavid
endavid / equality-function.swift
Created February 26, 2020 18:02
#swift equality functions for #medium
func ==(lhs: Bread, rhs: Bread) -> Bool {
return lhs.rating == rhs.rating
}
b1 == b2 // true
func ==(lhs: Cheese, rhs: Cheese) -> Bool {
return lhs.rating == rhs.rating
}
c1 == c2 // true
c1 == c4 // false
cheeses.contains(c1) // still an error! not Equatable
@endavid
endavid / equatable.swift
Created February 26, 2020 18:04
#swift equatable example for #medium
class Cheese: Equatable {
static func == (lhs: Cheese, rhs: Cheese) -> Bool {
return lhs.rating == rhs.rating
}
let rating : Int
init(rating: Int) {
self.rating = rating
}
}
/// ...