Skip to content

Instantly share code, notes, and snippets.

View MaximeFrancoeur's full-sized avatar
🎯
Focusing

0xMaxPower MaximeFrancoeur

🎯
Focusing
  • Canada
View GitHub Profile
@MaximeFrancoeur
MaximeFrancoeur / routerStateEq.js
Created December 17, 2014 04:05
Angular Directive that analyses the current ui-router $state and allows us to apply a css class depending on true/false
'use strict';
/**
* router-state-eq Directive
*
* What does this directive do?
* Analyses the current $state and allows us to apply a css class depending on true/false
*
* How to use it?
* Apply the router-state-eq="" attribute to the DOM element you want to style
@MaximeFrancoeur
MaximeFrancoeur / country_dump_postgresql.sql
Last active June 17, 2019 21:33
Country dump PostgreSQL
INSERT INTO country (id, iso, name_const, name, iso3, numcode, phonecode) VALUES
(1, 'AF', 'AFGHANISTAN', 'Afghanistan', 'AFG', 4, 93),
(2, 'AL', 'ALBANIA', 'Albania', 'ALB', 8, 355),
(3, 'DZ', 'ALGERIA', 'Algeria', 'DZA', 12, 213),
(4, 'AS', 'AMERICAN SAMOA', 'American Samoa', 'ASM', 16, 1684),
(5, 'AD', 'ANDORRA', 'Andorra', 'AND', 20, 376),
(6, 'AO', 'ANGOLA', 'Angola', 'AGO', 24, 244),
(7, 'AI', 'ANGUILLA', 'Anguilla', 'AIA', 660, 1264),
(8, 'AQ', 'ANTARCTICA', 'Antarctica', NULL, NULL, 0),
var AWS = require("aws-sdk");
var DOC = require("dynamodb-doc");
var path = require('path');
var util = require('util');
var _ = require('lodash');
var async = require('async');
var internals = {};
@MaximeFrancoeur
MaximeFrancoeur / mockito_class_with_abstract.java
Created April 27, 2015 15:37
Mockito How to mock only the call of a method of the superclass ? No, Mockito does not support this. If you really don't have a choice for refactoring you can mock/stub everything in the super method call :
class BaseService {
public void save(){
validate();
}
}
public ChildService extends BaseService{
public void save(){
super.save()
load();
@MaximeFrancoeur
MaximeFrancoeur / example_argument_captor_mockito.java
Created April 28, 2015 12:39
Complex Stubbing with Mockito for Java
@Mock private SmtpConnection smtpConnection;
private void mockSmtpConnection() {
final ArgumentCaptor<String> recipient = ArgumentCaptor.forClass(String.class);
final ArgumentCaptor<String> subject = ArgumentCaptor.forClass(String.class);
final ArgumentCaptor<String> body = ArgumentCaptor.forClass(String.class);
when(smtpConnection.setRecipient(recipient.capture()))
.thenReturn(smtpConnection);
when(smtpConnection.setSubject(subject.capture()))
public class PomVersion {
final private static Logger LOGGER = LogManager.getLogger(PomVersion.class);
final static String VERSION = loadVersion();
private static String loadVersion() {
Properties properties = new Properties();
try {
InputStream inStream = PomVersion.class.getClassLoader().getResourceAsStream("version.properties");
properties.load(inStream);
@MaximeFrancoeur
MaximeFrancoeur / elastic_beanstalk_external_sessions.md
Last active August 29, 2015 14:27 — forked from mlconnor/elastic_beanstalk_external_sessions.md
Analaysis and recommendation for externalizing session in Elastic Beanstalk using Tomcat and memcached.

Session Management in an Autoscaling Environment

Problem Statement

User sessions in J2EE and LAMP stacks have traditionally been handled in memory by the application server handling the user request. Because of that, load balancers have been configured to use sticky sessions. By sticky sessions we mean that once the user has visited the site, they will be assigned an app server and will return to that server for subsequent requests. The load balancers typically handle that by referencing the users session cookie.

Elastic cloud environments differ from traditional server configurations in that they have a variable number of servers based on traffic loads whereas traditional configurations had a fixed number of servers. When traffic volumes decline it is necessary to vaporize servers. In doing so, we would lose user sessions (essentially forcing a logout) unless we come up with a new strategy for session management.

A new approach

After much research, it is clear that the best

@MaximeFrancoeur
MaximeFrancoeur / HMAC.java
Last active November 18, 2021 08:50
Generating HMAC MD5/SHA1/SHA256 etc in Java
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
import java.io.UnsupportedEncodingException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
public class HMAC {
public static void main(String[] args) throws Exception {
System.out.println(hmacDigest("The quick brown fox jumps over the lazy dog", "key", "HmacSHA1"));
}
@MaximeFrancoeur
MaximeFrancoeur / convert_end_line_windows_to_linux
Created September 29, 2016 00:20
Convert CRLF to LF for OS X
find ./ -type f -exec perl -pi -e 's/\r\n|\n|\r/\n/g' {} \;
@MaximeFrancoeur
MaximeFrancoeur / HelloCovariance.java
Created October 25, 2017 20:18 — forked from AlainODea/HelloCovariance.java
Exception in thread "main" java.lang.NoSuchMethodError: java.util.concurrent.ConcurrentHashMap.keySet()Ljava/util/concurrent/ConcurrentHashMap$KeySetView;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
public class HelloCovariance {
public static void main(String[] args) {
ConcurrentHashMap<String, String> properties = new ConcurrentHashMap<>();
Set<String> keySet = properties.keySet();
}
}