Skip to content

Instantly share code, notes, and snippets.

View dacap's full-sized avatar
🎨
Programming

David Capello dacap

🎨
Programming
View GitHub Profile
@dacap
dacap / gist:2155047
Created March 22, 2012 01:35
More closure magic in pseudo-code
// Holly crap! Now we can give the "sum_and_count" function as a parameter.
FUNCTION Calculate_average ( sum_and_count, N1, N2, ..., NN )
LOCAL VARIABLE sum = 0
LOCAL VARIABLE count = 0
FOR_EACH N = N1, N2, ..., NN
CALL_THE_FOLLOWING_FUNCTION sum_and_count ( N )
RETURN num / count
END FUNCTION
@dacap
dacap / emacs-c++key-stats.txt
Created May 23, 2012 23:38
dacap's key stats 2012-05-23
950054 16.84% self-insert-command
756545 13.41% next-line
675163 11.97% previous-line
...
213058 3.78% move-beginning-of-line
201271 3.57% subword-forward
...
101016 1.79% subword-backward
97459 1.73% c-forward-subword
94503 1.68% backward-sexp
@dacap
dacap / test.cpp
Created June 12, 2012 02:00
Emacs C++ navigation test
namespace my_namespace {
void func1() {
}
void func2() {
}
class MyClass {
public:
(defun slick-shrink-whitespace ()
"Replaces three Emacs functions in just one:
- Calls `delete-blank-lines' when used in a blank line
- Calls `just-one-space' when used in a sequence of whitespaces
- Calls `delete-horizontal-space' when used in one whitespace
"
(interactive)
(skip-chars-forward " \t")
(let ((endcol (current-column))
(iseol (eolp)))
@dacap
dacap / skia-assert.md
Last active March 30, 2016 18:32
Skia assert failed on SkBitmapDevice.cpp Raw

If you get this error:

../../src/core/SkBitmapDevice.cpp:83: fatal error: ""valid_for_bitmap_device(bitmap.info(), nullptr)""
aborted (core dumped)

It might happen because kN32_SkColorType=kBGRA_8888_SkColorType in your code and kN32_SkColorType=kRGBA_8888_SkColorType on Skia side (in valid_for_bitmap_device()).

On Linux, you need to define -DSK_SAMPLES_FOR_X when you compile your own program, this will makekN32_SkColorType=kRGBA_8888_SkColorType.

@dacap
dacap / blog1.md
Last active March 31, 2016 05:00
var fs = require('fs');
var jay = JSON.parse(fs.readFileSync('jay.json', 'utf8'));
var robin = JSON.parse(fs.readFileSync('robin.json', 'utf8'));
var smile = JSON.parse(fs.readFileSync('smile.json', 'utf8'));
var data = { "jay": { "tags": jay.meta.frameTags,
"layers": jay.meta.layers },
"robin": { "tags": robin.meta.frameTags,
"layers": robin.meta.layers },
"smile": { "tags": smile.meta.frameTags,
@dacap
dacap / crash.cpp
Created August 11, 2016 00:38
C++ crash
#include <iostream>
#include <string>
struct Person {
std::string name;
};
int main() {
Person* p = nullptr;
std::cout << (p ? p->name: nullptr) << "\n";
@dacap
dacap / new_sprite.xml
Created August 17, 2016 15:54
Aseprite pixel aspect ratio hack
<check id="advanced_check" text="Advanced Options" />
<vbox id="advanced">
<grid columns="2">
<label text="Pixel Ratio:" />
<combobox id="pixel_ratio" cell_align="horizontal">
<listitem text="Square Pixels (1:1)" value="1:1" />
<listitem text="Double-wide Pixels (2:1)" value="2:1" />
<listitem text="Double-high Pixels (1:2)" value="1:2" />
<listitem text="NES/SNES (8:7)" value="8:7" />
</combobox>
@dacap
dacap / extra-zoom-levels.aseprite-keys
Created December 29, 2016 21:26
Aseprite file with an extra zoom level (600%) in number keys 1,2,3,4,5,6,7
<?xml version="1.0" encoding="utf-8" ?>
<keyboard version="1">
<commands>
<key command="Zoom" shortcut="1"><param name="percentage" value="100" /></key>
<key command="Zoom" shortcut="2"><param name="percentage" value="200" /></key>
<key command="Zoom" shortcut="3"><param name="percentage" value="400" /></key>
<key command="Zoom" shortcut="4"><param name="percentage" value="600" /></key>
<key command="Zoom" shortcut="5"><param name="percentage" value="800" /></key>
<key command="Zoom" shortcut="6"><param name="percentage" value="1600" /></key>
<key command="Zoom" shortcut="7"><param name="percentage" value="3200" /></key>