Skip to content

Instantly share code, notes, and snippets.

View H2CO3's full-sized avatar
🦀

Árpád Goretity  H2CO3

🦀
View GitHub Profile
@H2CO3
H2CO3 / SDL2_gfx_gradients.diff
Created April 6, 2015 11:05
Adding gradient drawing primitives to SDL2_gfx
Index: SDL2_gfxPrimitives.c
===================================================================
--- SDL2_gfxPrimitives.c (revision 29)
+++ SDL2_gfxPrimitives.c (working copy)
@@ -3788,3 +3788,288 @@
/* Draw polygon */
return filledPolygonRGBA(renderer, px, py, 4, r, g, b, a);
}
+
+/////// Gradient Drawing //////
@H2CO3
H2CO3 / pong.spn
Created April 24, 2015 13:11
Pong in Sparkling, in 40 minutes
let SDL = dynld("sdl2");
let w = SDL::OpenWindow("Pong", 640, 480);
var paddle = {
"x": 0,
"y": 0,
"w": 100,
"h": 40
};
@H2CO3
H2CO3 / Ubuntu-Macbook-Setup.md
Created April 27, 2015 18:43
Ubuntu Retina MacBook Pro mid-2014 UI and general Setup

Set up Wi-Fi:

sudo apt-get install bcmwl-kernel-source
sudo modprobe wl

in the file /etc/modules, add the line

wl

in order to start up the wireless service upon reboot.

let SDL = dynld("sdl2");
var timers = {};
let timerWithEvent = fn (dt, callback) {
let tmr = SDL::StartTimer(dt);
timers[tmr] = callback;
};
#include <memory>
#include <cstdio>
static void foo(std::unique_ptr<int> p)
{
printf("%d\n", *p);
}
int main()
{
###### 'C-style' syntax (braces and semicolons) ######
-> return statements needed (except in one-expression lambdas)
// function := 'fn' ['<' Types... '>'] ident '(' Args... ')' ['->' RetType] block-statement
// local-function := function
// lambda := '(' args... ')' '->' statement
// args := [ arg { , arg } ]
// arg := ident [['::'] type]
// if 'statement' is an expression, then automatically 'return' it!
// 'statement' can be a block as well! (-> multiple statements...)
function drawShape(ctx, xoff, yoff) {
ctx.beginPath();
ctx.moveTo(206 + xoff, 86 + yoff);
ctx.bezierCurveTo(263 + xoff, 33 + yoff, 381 + xoff, 65 + yoff, 348 + xoff, 160 + yoff);
ctx.bezierCurveTo(328 + xoff, 218 + yoff, 251 + xoff, 194 + yoff, 206 + xoff, 279 + yoff);
ctx.bezierCurveTo(161 + xoff, 194 + yoff, 84 + xoff, 218 + yoff, 64 + xoff, 160 + yoff);
ctx.bezierCurveTo(31 + xoff, 65 + yoff, 149 + xoff, 33 + yoff, 206 + xoff, 86 + yoff);
ctx.stroke();
}
@H2CO3
H2CO3 / inherit.spn
Created August 22, 2015 07:07
prototypal inheritance demo in Sparkling
let base = {
foo: fn (self) {
stdout.printf("base::foo(self.type = %s)\n", self.type);
},
type: "base"
};
let derived = {
super: base,
bar: fn { print("derived::bar"); },
'reggelt!
gyors language design kérdés null pointerekkel kapcsolatban:
iOS miatt sokáig Objective-C-ben dolgoztam, és megszoktam (nagyon kényelmes), hogy a null objektumon
való metódushívás nem száll el (segfault/NullPointerException), hanem a visszatérési típus nulla értékét
(pl. int-nél 0, pointernél null, stb.) adja vissza.
nem nagyon futottam még bele olyan hibába, ahol ez a viselkedés bugot okozott volna,
sőt, az esetek többségében kifejezetten kívánatos.
> Object Oriented Programming (OOP) as an idea has been oversold. […] Extremist languages like Java force you to think of everything in terms of objects.
Yes, OOP has been oversold. But that’s not the problem of OOP; that’s the problem of incompetent programmers who are trying to use one tool for everything. Of course what Java doing is extremism too (also, see the amount of incompetent programmers in each language… Java is considered an “industrial” language, so it’s perhaps only C and C++ that have more utterly incompetent users than Java; people just want to be rich.) But nobody said you have to use Java! In fact, I think you should not use Java. Having to write an entire class just to possess a main function? Stupid! There are better languages that support OO yet don’t *force* you into the OO mindset, e.g. Objective-C or C++.
> State is not your friend, state is your enemy. Changes to state make programs harder to reason about […]
Except when it’s the declarative approach that’s harder to reason about.