This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function scaleToFit ( | |
contentWidth, | |
contentHeight, | |
containerWidth, | |
containerHeight | |
) { | |
var scale = Math.min(containerWidth / contentWidth, containerHeight / contentHeight) | |
return { | |
x: containerWidth / 2 - contentWidth * scale / 2, | |
y: containerHeight / 2 - contentHeight * scale / 2, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function uuidv4() { | |
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) { | |
var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8); | |
return v.toString(16); | |
}); | |
} | |
console.log(uuidv4()); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdlib.h> | |
#include <windows.h> | |
#include <gdiplus.h> | |
Bitmap* loadBitmap(char* file) | |
{ | |
int length = strlen(file) + 1; | |
wchar_t* fileW = (wchar_t*) malloc(length * sizeof(wchar_t)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdlib.h> | |
#include <string.h> | |
typedef struct Entry { | |
char* key; | |
void* value; | |
int next; | |
} Entry; | |
typedef struct Map { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdlib.h> | |
#include <string.h> | |
#define CAPACITY 100000 | |
typedef struct Entry { | |
char* key; | |
void* value; | |
struct Entry* next; | |
} Entry; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdlib.h> | |
#include <string.h> | |
#define CAPACITY 4096 | |
typedef struct Entry { | |
char* key; | |
void* value; | |
struct Entry* next; | |
} Entry; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <windows.h> | |
void SleepSync(int targetFps) | |
{ | |
static DWORD previous = 0; | |
if (previous == 0) | |
previous = GetTickCount(); | |
LONGLONG current = GetTickCount(); | |
LONGLONG sleepTime = (1000 / targetFps) - (current - previous); | |
previous = current; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include "sb.c" | |
void main() | |
{ | |
SB* sb = sb_new(); | |
sb_add(sb, "["); | |
char next = 0; | |
for (int i = 1; i <= 10; ++i) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int hashc(char* p, int sz) | |
{ | |
if (!sz) | |
return 0; | |
sz /= sizeof(char); | |
int h = 1; | |
for (int i = 0; i < sz; ++i) | |
h = 31 * h + *(p + i); | |
return h; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.*; | |
import java.util.Map.*; | |
import java.util.regex.*; | |
@SuppressWarnings("unchecked") | |
public final class JSON { | |
private JSON() { | |
} |