Skip to content

Instantly share code, notes, and snippets.

@refactor
refactor / atom_4_core
Created August 31, 2012 03:21
Intel(R) Atom(TM) CPU N2800 @ 1.86GHz (8GB memory)
erl
Erlang R15B01 (erts-5.9.1) [source] [64-bit] [smp:4:4] [async-threads:0] [kernel-poll:false]
Eshell V5.9.1 (abort with ^G)
1> erlang:system_info(cpu_topology).
[{processor,[{core,[{thread,{logical,0}},
{thread,{logical,1}}]},
{core,[{thread,{logical,2}},{thread,{logical,3}}]}]}]
@refactor
refactor / cpuinfo
Created August 31, 2012 03:32
Intel(R) Core(TM)2 Quad CPU Q8300 @ 2.50GHz
processor : 0
vendor_id : GenuineIntel
cpu family : 6
model : 23
model name : Intel(R) Core(TM)2 Quad CPU Q8300 @ 2.50GHz
stepping : 10
microcode : 0xa07
cpu MHz : 2493.898
cache size : 2048 KB
physical id : 0
@refactor
refactor / Quirks of C.md
Created September 12, 2018 06:36 — forked from fay59/Quirks of C.md
Quirks of C

Here's a list of mildly interesting things about the C language that I learned over time. There are many more mildly interesting features of C++, but the language is literally known for being weird, whereas C is usually considered smaller and simpler, so this is (almost) only about C.

1. Combined type and variable/field declaration, inside a struct scope [https://godbolt.org/g/Rh94Go]

struct foo {
   struct bar {
       int x;
   } baz;
};
@refactor
refactor / osr_test.c
Last active January 20, 2019 09:33
GDAL's coordinate system demo
#include <ogr_srs_api.h>
#include <cpl_conv.h>
int main(void) {
OGRSpatialReferenceH sr = OSRNewSpatialReference(NULL);
OSRImportFromEPSG(sr, 3857);
// OSRSetWellKnownGeogCS(sr, "WGS84");
char* ppsz;
OSRExportToPrettyWkt(sr, &ppsz, FALSE);
printf("3857.wkt: \n%s\n", ppsz);
@refactor
refactor / autowarp_test.c
Last active January 27, 2019 01:49
test GDALAutoCreateWarpedVRT
#include <cpl_conv.h>
#include <ogr_srs_api.h>
#include <gdalwarper.h>
/*
* https://www.gdal.org/warptut.html
*/
int main()
{
GDALAllRegister();
@refactor
refactor / xmerl_test.erl
Last active January 21, 2019 01:33
try to modify xml, add some element node
-include_lib("xmerl/include/xmerl.hrl").
%% tuple -> xml-erl
TL = {filemeta,[{id,'/Foo'},{bar,12111111113}], [{name,["11"]},{age,["1"]}]}.
XmlDoc = xmerl:export_simple([TL], xmerl_xml).
%% xml-erl -> tuple
TL = xmerl_lib:simplify_element(XmlDoc).
#define FL_ARG_COUNT(...) FL_INTERNAL_ARG_COUNT_PRIVATE(0, ##__VA_ARGS__, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0)
#define FL_INTERNAL_ARG_COUNT_PRIVATE(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, N, ...) N
#define FL_CONCAT_(l,r) l ## r
#define FL_CONCAT(l,r) FL_CONCAT_(l,r)
extern VkImageView _createImageView(VkDevice device, VkImage image, VkFormat format, VkImageAspectFlags aspectFlags);
#define _CREATE_IMAGE_VIEW_1(DEV,IMG) _createImageView(DEV,IMG,VK_FORMAT_R8G8B8A8_SRGB,VK_IMAGE_ASPECT_COLOR_BIT)
#define _CREATE_IMAGE_VIEW_2(DEV,IMG, fmt) _createImageView(DEV,IMG,fmt,VK_IMAGE_ASPECT_COLOR_BIT)
> io_lib:format("~2.16.0B", [15]).
0F
> io_lib:format("~2.16.#b", [15]).
"#f"
> io_lib:format("~2.2.#b", [1]).
"#1"
> io_lib:format("~2.2.#b", [2]).
"10"
@refactor
refactor / gist:4ee13beff550f5d6c016d4b326020b8b
Created July 16, 2023 15:16
erl shell history base on direnv
export ERL_AFLAGS="-kernel shell_history_path '\".erl_history\"' -kernel shell_history enabled"
@refactor
refactor / gist:539c567bedfc80e1349fcd93a89a83ce
Created August 2, 2023 03:04
How to overload a function in C, by parameter type & number
void scale_circ(Circle_s c[static 1], double scale) {
c->radius *= scale;
}
void scale_rect(Rectangle_s r[static 1], double scale) {
r->w *= scale;
r->h *= scale;
}
#define scale(obj, scale) \