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 / Working GDB on macOS 11.md
Created December 15, 2021 01:52 — forked from mike-myers-tob/Working GDB on macOS 11.md
Steps to get GDB actually working in April 2021 on macOS

Debug with GDB on macOS 11

The big reason to do this is that LLDB has no ability to "follow-fork-mode child", in other words, a multi-process target that doesn't have a single-process mode (or, a bug that only manifests when in multi-process mode) is going to be difficult or impossible to debug, especially if you have to run the target over and over in order to make the bug manifest. If you have a repeatable bug, no big deal, break on the fork from the parent process and attach to the child in a second lldb instance. Otherwise, read on.

Install GDB

Don't make the mistake of thinking you can just brew install gdb. Currently this is version 10.2 and it's mostly broken, with at least two annoying bugs as of April 29th 2021, but the big one is https://sourceware.org/bugzilla/show_bug.cgi?id=24069

$ xcode-select install  # install the XCode command-line tools
@MaximeFrancoeur
MaximeFrancoeur / learn.lua
Created September 12, 2019 21:01 — forked from tylerneylon/learn.lua
Learn Lua quickly with this short yet comprehensive and friendly script. It's written as both an introduction and a quick reference. It's also a valid Lua script so you can verify that the code does what it says, and learn more by modifying and running this script in your Lua interpreter.
-- Two dashes start a one-line comment.
--[[
Adding two ['s and ]'s makes it a
multi-line comment.
--]]
----------------------------------------------------
-- 1. Variables and flow control.
----------------------------------------------------
@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();
}
}
@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 / 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 / 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

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 / 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()))
@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();