Skip to content

Instantly share code, notes, and snippets.

@carlhoerberg
carlhoerberg / reconnect.js
Created May 13, 2015 14:45
How to build reconnect logic for amqplib
var amqp = require('amqplib/callback_api');
// if the connection is closed or fails to be established at all, we will reconnect
var amqpConn = null;
function start() {
amqp.connect(process.env.CLOUDAMQP_URL + "?heartbeat=60", function(err, conn) {
if (err) {
console.error("[AMQP]", err.message);
return setTimeout(start, 1000);
}
@yoavniran
yoavniran / ultimate-ut-cheat-sheet.md
Last active March 24, 2025 20:20
The Ultimate Unit Testing Cheat-sheet For Mocha, Chai, Sinon, and Jest
@joyrexus
joyrexus / README.md
Last active June 8, 2023 07:45
form-data vs -urlencoded

Nice answer on stackoverflow to the question of when to use one or the other content-types for POSTing data, viz. application/x-www-form-urlencoded and multipart/form-data.

“The moral of the story is, if you have binary (non-alphanumeric) data (or a significantly sized payload) to transmit, use multipart/form-data. Otherwise, use application/x-www-form-urlencoded.”


Matt Bridges' answer in full:

The MIME types you mention are the two Content-Type headers for HTTP POST requests that user-agents (browsers) must support. The purpose of both of those types of requests is to send a list of name/value pairs to the server. Depending on the type and amount of data being transmitted, one of the methods will be more efficient than the other. To understand why, you have to look at what each is doing

@alexaleluia12
alexaleluia12 / Java.java
Last active February 11, 2024 12:05
Benchmarck (comparação de velocidade) Python, C, Java, Javascript, C++, Kotlin, Go
public class Java {
public static void main(String[] args) {
int count = 0;
for(int i=0; i<1000; i++){
count += i;
}
System.out.println(count); // corrigido conforme comentario
}
}
@staltz
staltz / introrx.md
Last active May 24, 2025 19:53
The introduction to Reactive Programming you've been missing
@mrkline
mrkline / c_sharp_for_python.md
Last active September 2, 2024 15:51
An intro to C# for a Python developer. Made for one of my coworkers.

C# For Python Programmers

Syntax and core concepts

Basic Syntax

  • Single-line comments are started with //. Multi-line comments are started with /* and ended with */.

  • C# uses braces ({ and }) instead of indentation to organize code into blocks. If a block is a single line, the braces can be omitted. For example,

@MercuryRising
MercuryRising / redisCache.py
Created October 13, 2012 20:06
Caching Files
import redis
import time
import random
def load_file(fp, fpKey, r, expiry):
with open(fp, "rb") as f:
data = f.read()
p = r.pipeline()
p.set(fpKey, data)
@MikeRogers0
MikeRogers0 / validate-email.php
Created June 16, 2012 17:09
How to validate an email address with PHP
<?php
function validEmail($email){
// Check the formatting is correct
if(filter_var($email, FILTER_VALIDATE_EMAIL) === false){
return FALSE;
}
// Next check the domain is real.
$domain = explode("@", $email, 2);
return checkdnsrr($domain[1]); // returns TRUE/FALSE;
@thiagoghisi
thiagoghisi / CodingDojo_DicasParaNovosGrupos
Created September 30, 2011 23:24
Tutorial/Dicas para montar um grupo de Coding Dojo na sua região
1ª Criar um grupo de discussão; (Sugestão: Google Groups)
2ª Divulgar o grupo para o pessoal da sua região nas redes socias que você participa;
(Dica: Divulgação no Twitter é essencial)
3ª Fazer um spam para todos os seus contatos da área da sua região convidando para o grupo;
4ª Se você não for muito influente nas redes sociais ou não tiver muitos contatos,
solicitar para alguém que tenha ajudar na divulgação do grupo;
(Dica: O que vale nesse momento é fazer bastante barulho)
@bergantine
bergantine / gist:1171682
Last active July 11, 2023 01:42
Python Image Encoding in Data URI Scheme Base 64. #python #base64
data_uri = open("sample.png", "rb").read().encode("base64").replace("\n", "")
# HTML Image Element
img_tag = '<img alt="" src="data:image/png;base64,{0}">'.format(data_uri)
print img_tag
# CSS Background Image
css = 'background-image: url(data:image/png;base64,{0});'.format(data_uri)
print css