Skip to content

Instantly share code, notes, and snippets.

View felipecrv's full-sized avatar
🌴
On vacation

Felipe Oliveira Carvalho felipecrv

🌴
On vacation
View GitHub Profile
# Hash, displace, and compress: http://cmph.sourceforge.net/papers/esa09.pdf
# This is expected linear time for any seeded hash function that acts like a random hash function (universality isn't enough).
# (Actually, the code as written is O(n log n) when targeting 100% load. It's O(n) when targeting any smaller load factor.)
# You can make keys_per_bucket higher than the default of 4 but construction time will start to increase dramatically.
# The paper this is based on compresses the seeds (so the fact that the algorithm tries seeds in increasing order is important)
# which brings the representation size close to the information-theoretical minimum. I don't do any of that here, but it could
# be done as a postprocess.
def make_perfect_hash(keys, load_factor=1.0, keys_per_bucket=4, rhash=murmurhash, max_seed=1000000):
m = int(len(keys) / load_factor)
r = int(len(keys) / keys_per_bucket)
// Baseline version without prefetch
static const LRMEntry * lrm_search_one_basic(const LRM * lrm, const U8 * ptr)
{
LRM_hash_t hash = lrm_hash8(ptr);
// Jump-in: narrow down the search interval using the jump table
LRM_hash_t ji = hash >> lrm->jumpInShift;
S32 jump1 = lrm->jumpIn[ji];
S32 jump2 = lrm->jumpIn[ji + 1];
@negrinho
negrinho / latency.txt
Created July 16, 2018 21:11 — forked from jboner/latency.txt
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers Simplified (~2012)
---------------------------------- log2 log10
L1 cache reference 0 0 ~ 1 ns
Branch mispredict 3 1
L2 cache reference 4 1
Mutex lock/unlock 6 2
Main memory reference 8 2
Compress 1K bytes with Zippy 13 4
Send 1K bytes over 1 Gbps network 14 4
Read 4K randomly from SSD* 18 5
@lequanghuylc
lequanghuylc / pure-react.md
Last active January 17, 2023 14:13
[Using React & React Native without State management library] #article #react

It’s common these day when React & React Native developers use State management library (like Redux). I’ve been using React & React Native for a while now and found out that Pure React is actually not bad. In this article I will share my way of doing things with React & React Native purely, without State management library (represented by Redux). 

For those of you who are struggling learning Redux, because of the overwhelming of the whole React/JSX/Babel/Webpack/Native Component/Native Module/.. and have to add Redux to the list just to solve some of React problems, or because of the high learning curve of Redux, I hope you find this article helpful.

Some of React problems with State Management

Assuming you have some knowledge of React, I will jump right in the problems that most of us encoutered at the beginning of time learning React:

  • Flow pass data down, pass event up makes us to pass data & function via props and it's hard to manage when amount of props gets huge. (Comunication between component
#define BINKGL_LIST \
/* ret, name, params */ \
GLE(void, LinkProgram, GLuint program) \
GLE(void, GetProgramiv, GLuint program, GLenum pname, GLint *params) \
GLE(GLuint, CreateShader, GLenum type) \
GLE(void, ShaderSource, GLuint shader, GLsizei count, const GLchar* const *string, const GLint *length) \
GLE(void, CompileShader, GLuint shader) \
GLE(void, GetShaderiv, GLuint shader, GLenum pname, GLint *params) \
GLE(void, GetShaderInfoLog, GLuint shader, GLsizei bufSize, GLsizei *length, GLchar *infoLog) \
GLE(void, DeleteShader, GLuint shader) \
@danharper
danharper / CancellationTokenSource.js
Last active January 7, 2024 17:58
JavaScript "CancellationToken" for cancelling Async/Promise functions
const CANCEL = Symbol();
class CancellationToken {
constructor() {
this.cancelled = false;
}
throwIfCancelled() {
if (this.isCancelled()) {
@mikelehen
mikelehen / generate-pushid.js
Created February 11, 2015 17:34
JavaScript code for generating Firebase Push IDs
/**
* Fancy ID generator that creates 20-character string identifiers with the following properties:
*
* 1. They're based on timestamp so that they sort *after* any existing ids.
* 2. They contain 72-bits of random data after the timestamp so that IDs won't collide with other clients' IDs.
* 3. They sort *lexicographically* (so the timestamp is converted to characters that will sort properly).
* 4. They're monotonically increasing. Even if you generate more than one in the same timestamp, the
* latter ones will sort after the former ones. We do this by using the previous random bits
* but "incrementing" them by 1 (only in the case of a timestamp collision).
*/
#ifndef _SDL_opengl_load_h
#define _SDL_opengl_load_h
extern PFNGLBLENDCOLORPROC SDL_glBlendColor;
#define glBlendColor SDL_glBlendColor
extern PFNGLBLENDEQUATIONPROC SDL_glBlendEquation;
#define glBlendEquation SDL_glBlendEquation
extern PFNGLDRAWRANGEELEMENTSPROC SDL_glDrawRangeElements;
@cvogt
cvogt / gist:9239494
Last active September 9, 2019 01:30
Slick app architecture cheat sheet
// Please comment in case of typos or bugs
import scala.slick.driver.H2Driver._
val db = Database.for...(...)
case class Record( ... )
class Records(tag: Tag) extends Table[Record](tag,"RECORDS"){
...
def * = ... <> (Record.tupled,Record.unapply)
// place additional methods here which return values of type Column
@romannurik
romannurik / DrawInsetsFrameLayout.java
Created February 10, 2014 16:28
DrawInsetsFrameLayout — adding additional background protection for system UI chrome when using KitKat’s translucent decor flags.
/*
* Copyright 2014 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software