Skip to content

Instantly share code, notes, and snippets.

View saucecode's full-sized avatar

Julian saucecode

  • New Zealand
View GitHub Profile
@saucecode
saucecode / aoc3.c
Created December 3, 2017 11:59
my C99 solution to advent of code 2017 day 3 part 2
#include <stdint.h>
#include <stdio.h>
#include <string.h>
// returns the sum of all 8 adjacent cells to element [cy][cx] in a 2D array, with bounds checking
uint32_t setdata(uint32_t root_max, uint32_t data[][root_max], uint32_t cx, uint32_t cy){
uint32_t counter = 0;
if(cx + 1 < root_max){
counter += data[cy][cx+1];
if(cy - 1 >= 0)
@saucecode
saucecode / threeshears.py
Created June 12, 2017 09:58
an attempt at the three shears image rotation problem. Reads from first.png, outputs to out.png
import math
from PIL import Image, ImageDraw
input_image = Image.open("first.png")
width,height = input_image.size
second_image = Image.new('RGB', input_image.size)
third_image = Image.new('RGB', input_image.size)
output_image = Image.new('RGB', input_image.size)
# draw = ImageDraw.Draw(output_image)
@saucecode
saucecode / my_flask_program.py
Created December 31, 2016 06:50
how to correctly use a letsencrypt cert with flask
...
from OpenSSL import SSL
...
context = SSL.Context(SSL.TLSv1_2_METHOD)
context.use_privatekey_file('/etc/letsencrypt/live/DOMAIN.COM/privkey.pem')
context.use_certificate_chain_file('/etc/letsencrypt/live/DOMAIN.COM/fullchain.pem')
context.use_certificate_file('/etc/letsencrypt/live/DOMAIN.COM/cert.pem')
@saucecode
saucecode / compile.sh
Created December 30, 2016 17:44
dlopen example
g++ -fPIC -c hello.cpp
g++ -shared -o hello.so hello.o
g++ main.cpp -ldl
std::vector<projectile_t*> projectiles;
// ...
projectiles.erase(
std::remove_if(projectiles.begin(), projectiles.end(),
[](projectile_t *p){ return p->life <= 0.0; }),
projectiles.end()
);
@saucecode
saucecode / mykitexample.cpp
Last active November 17, 2021 10:00
mykitexample.cpp
#include <Kit/Window.hpp>
#include <Kit/Renderer.hpp>
#include <Kit/Quad.hpp>
#include <Kit/Light.hpp> // Lights..
#include <Kit/Camera.hpp> // Camera..
#include <Kit/Model.hpp> // Action!
int main(int argc, char *argv[]){
@saucecode
saucecode / challenge277.c
Created July 29, 2016 17:31
julia set generator for /r/dailyprogramming challenge 277 https://redd.it/4v5h3u
// challenge 277 hard 2016-07-29 /r/dailyprogrammer https://redd.it/4v5h3u
// compile: $ gcc -std=c99 challenge277.c -lm
// outputs to: fractal.tga
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <complex.h>
0 0 7 0 0 0 2 2 2 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 2 2 2
0 0 7 0 0 0 2 2 2 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 2 2 2 0 0 0
2 2 2 0 0 0 0 0 0 0 0 0 2 2 2
@saucecode
saucecode / challenge248.c
Last active January 5, 2016 20:24
first working version
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define PI 3.14159265
// https://www.reddit.com/r/dailyprogrammer/comments/3zfajl/20160104_challenge_248_easy_draw_me_like_one_of/
struct rgb_t {
unsigned char r;
import urllib2, json, os, time
albumurl = raw_input('imgur album url: ')
foldername = albumurl.split('/')[-1].split('#')[0]
if not os.path.exists(foldername+'/'): os.mkdir(foldername+'/')
print 'downloading html...'
albumhtml = urllib2.urlopen(albumurl).read()
jdata = '{"count":'+albumhtml.split("{\"count\":")[1].split('\n')[0][:-1]
data = json.loads(jdata)
print 'going to download',len(data['items']),'images into folder:',foldername