Skip to content

Instantly share code, notes, and snippets.

View kgabis's full-sized avatar

Krzysztof Gabis kgabis

View GitHub Profile
@kgabis
kgabis / rast.c
Created January 7, 2020 21:32
Rasterise triangle
#define EDGE_FUNC(a, b, c) (((c).x - (a).x) * ((b).y - (a).y) - ((c).y - (a).y) * ((b).x - (a).x))
static void rasterize_triangle(old_renderer_t *r, const scene_t *scene, const triangle_t *t) {
vec3_t a = t->a, b = t->b, c = t->c;
float inv_az = 1.0f/a.z;
float inv_bz = 1.0f/b.z;
float inv_cz = 1.0f/c.z;
// projected
@kgabis
kgabis / kek.cpp
Created August 8, 2016 19:46
keksimus maksimus
#include <stdlib.h> // kek > kek.ppm
#include <stdio.h>
#include <math.h>
#define u f R(){
typedef int i;typedef float f;struct v{
f x,y,z;v operator+(v r){return v(x+r.x
,y+r.y,z+r.z);}v operator*(f r){return
v(x*r,y*r,z*r);}f operator%(v r){return
x*r.x+y*r.y+z*r.z;}v(){}v operator^(v r
){return v(y*r.z-z*r.y,z*r.x-x*r.z,x*r.
@kgabis
kgabis / copy
Created February 7, 2015 23:48
Copy/paste util
#!/bin/bash
cwd=$(pwd)
rm /tmp/.copy_tmp
for var in "$@"
do
echo "$cwd/$var" >> /tmp/.copy_tmp
done
@kgabis
kgabis / tests.c
Created November 22, 2014 20:54
Parson tests with fabs
/*
Parson ( http://kgabis.github.com/parson/ )
Copyright (c) 2012 - 2014 Krzysztof Gabis
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
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
@kgabis
kgabis / dropboxpro.md
Last active May 18, 2016 22:03
Weird pricing of Dropbox Pro

Last week Dropbox introduced Dropbox Pro with 1TB storage space (and some other cool features) for $99/year (or $9,99/month), which is a pretty good deal (Google Drive 1TB also costs $99,99/year). The problem: it's not $99/year, but $130/year (or $13/month) if you happen to live in Europe. Instead of converting prices from dollars to euros, they just changed $ to €.

pricing

But that's not the best part. You can buy it cheaper if you use Dropbox app on iOS.

pricing on iOS

Now it's only $118/year or $10/month, which is much cheaper than through their website (and they still have to give 30% of that to apple!). I guess we should thank apple for not allowing different pricing in different regions. So if you plan to upgrade to Dropbox Pro, do it through their mobile app.

@kgabis
kgabis / gist.md
Created July 30, 2014 17:00
Gist test

##About Parson is a lighweight json library written in C. This is a version in development (hence -devel suffix), it contains some features parson lacks, but API can and probably will change in future.

##Features

  • Full JSON support
  • Lightweight (only 2 files)
  • Simple API
  • Addressing json values with dot notation (similiar to C structs or objects in most OO languages, e.g. "objectA.objectB.value")
  • C89 compatible
1.368074 2.435437 -0.227403 1.400000 2.400000 0.000000 1.381968 2.400000 -0.229712
1.400000 2.400000 0.000000 1.368074 2.435437 -0.227403 1.385925 2.435437 0.000000
1.316296 2.435437 -0.442166 1.381968 2.400000 -0.229712 1.329664 2.400000 -0.446656
1.381968 2.400000 -0.229712 1.316296 2.435437 -0.442166 1.368074 2.435437 -0.227403
1.233252 2.435437 -0.641628 1.329664 2.400000 -0.446656 1.245776 2.400000 -0.648144
1.329664 2.400000 -0.446656 1.233252 2.435437 -0.641628 1.316296 2.435437 -0.442166
1.121601 2.435437 -0.823129 1.245776 2.400000 -0.648144 1.132992 2.400000 -0.831488
1.245776 2.400000 -0.648144 1.121601 2.435437 -0.823129 1.233252 2.435437 -0.641628
0.984007 2.435437 -0.984007 1.132992 2.400000 -0.831488 0.994000 2.400000 -0.994000
1.132992 2.400000 -0.831488 0.984007 2.435437 -0.984007 1.121601 2.435437 -0.823129
@kgabis
kgabis / colinear.cpp
Last active December 28, 2015 23:19
Colinear points tests.
//
// colinear.cpp
// AlgosLabs
//
// Created by Krzysztof Gabis on 20.11.2013.
// Copyright (c) 2013 Krzysztof Gabis. All rights reserved.
//
#include "colinear.h"
@kgabis
kgabis / remove_comments.c
Created November 20, 2013 09:33
replaces comments with spaces
void json_remove_comments(char *string, const char *start_token, const char *end_token) {
int in_string = 0, escaped = 0, i;
char *ptr = NULL, c;
size_t start_token_len = strlen(start_token);
size_t end_token_len = strlen(end_token);
if (start_token_len == 0 || end_token_len == 0)
return;
while ((c = *string) != '\0') {
if (c == '\\' && !escaped) {
escaped = 1;
@kgabis
kgabis / square.cu
Created November 3, 2013 17:46
Square kernel in CUDA (from udacity)
#include <stdio.h>
__global__ void square(float * d_out, float * d_in){
int idx = threadIdx.x;
float f = d_in[idx];
d_out[idx] = f * f;
}
int main(int argc, char ** argv) {
const int ARRAY_SIZE = 64;