Skip to content

Instantly share code, notes, and snippets.

View lscoder's full-sized avatar

Leonardo Campos lscoder

View GitHub Profile
@lscoder
lscoder / divisoresDespojados.js
Created June 8, 2019 04:21
Maratona de Programação da SBC - ACM ICPC - 2017 - Despojados
// 2. (Maratona de Programação da SBC – ACM ICPC – 2017) Despojados:
// Todo inteiro positivo pode ser escrito como um produto de potências de primos. Por
// exemplo, 252 = 2^2 X 3^2 X 7. Um inteiro é despojado se pode ser escrito como um produto de
//
// dois ou mais primos distintos, sem repetição. Por exemplo, 6 = 2 × 3 e 14 = 2 × 7 são
// despojados, mas 28 = 2^2 × 7, 1, 17 não são despojados.
// Entrada
// A entrada consiste de uma única linha que contém um inteiro N (1 ≤ N ≤ 1012).
// Saída
// Seu programa deve produzir uma única linha com um inteiro representando o número de
@lscoder
lscoder / what-forces-layout.md
Created April 15, 2018 03:26 — forked from paulirish/what-forces-layout.md
What forces layout/reflow. The comprehensive list.

What forces layout / reflow

All of the below properties or methods, when requested/called in JavaScript, will trigger the browser to synchronously calculate the style and layout*. This is also called reflow or layout thrashing, and is common performance bottleneck.

Element

Box metrics
  • elem.offsetLeft, elem.offsetTop, elem.offsetWidth, elem.offsetHeight, elem.offsetParent
  • elem.clientLeft, elem.clientTop, elem.clientWidth, elem.clientHeight
  • elem.getClientRects(), elem.getBoundingClientRect()
@lscoder
lscoder / noncritcss.md
Created December 17, 2015 15:23 — forked from scottjehl/noncritcss.md
Comparing two ways to load non-critical CSS

I wanted to figure out the fastest way to load non-critical CSS so that the impact on initial page drawing is minimal.

TL;DR: Here's the solution I ended up with: https://github.com/filamentgroup/loadCSS/


For async JavaScript file requests, we have the async attribute to make this easy, but CSS file requests have no similar standard mechanism (at least, none that will still apply the CSS after loading - here are some async CSS loading conditions that do apply when CSS is inapplicable to media: https://gist.github.com/igrigorik/2935269#file-notes-md ).

Seems there are a couple ways to load and apply a CSS file in a non-blocking manner:

@lscoder
lscoder / nginx.conf
Created September 30, 2015 01:45 — forked from plentz/nginx.conf
Best nginx configuration for improved security(and performance). Complete blog post here http://tautt.com/best-nginx-configuration-for-security/
# to generate your dhparam.pem file, run in the terminal
openssl dhparam -out /etc/nginx/ssl/dhparam.pem 2048
@lscoder
lscoder / SomeFragment.java
Last active September 20, 2015 19:49 — forked from joshdholtz/SomeFragment.java
Android Google Maps V2 - MapView in XML
public class SomeFragment extends Fragment {
MapView mapView;
GoogleMap map;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.some_layout, container, false);

Latency numbers every programmer should know

L1 cache reference ......................... 0.5 ns
Branch mispredict ............................ 5 ns
L2 cache reference ........................... 7 ns
Mutex lock/unlock ........................... 25 ns
Main memory reference ...................... 100 ns             
Compress 1K bytes with Zippy ............. 3,000 ns  =   3 µs
Send 2K bytes over 1 Gbps network ....... 20,000 ns  =  20 µs
SSD random read ........................ 150,000 ns  = 150 µs

Read 1 MB sequentially from memory ..... 250,000 ns = 250 µs

@lscoder
lscoder / CountSumRecursively.cs
Created September 25, 2012 02:37
Dado um vetor com 'n' números distintos, calcular quantas possibilidades existem para se obter a soma 's'
// Exemplo para se obter soma igual a 16 para os números 1, 2 e 5
static void Main(string[] args)
{
var startTime = DateTime.Now;
var count = CountSum(new[] { 1, 2, 5 }, 16);
var elapsedTime = DateTime.Now - startTime;
Console.WriteLine(string.Format("Sum count: {0}", count));
Console.WriteLine(string.Format("Executed in: {0} ms", elapsedTime.TotalMilliseconds));
Console.ReadKey(true);
@lscoder
lscoder / SimpleCombination
Last active October 2, 2015 03:08
Combinação simples (Triângulo de Pascal)
// Cálculo de combinação simples utilizando o triângulo de Pascal, onde:
//
// Relação de Stifel
//
// | n-1 | + | n-1 | = | n |
// | k-1 | | k | | k |
//
// Ex.: Quantidade de jogos da Mega Sena
// var quantity = SimpleCombination(60, 6);
//