Skip to content

Instantly share code, notes, and snippets.

View flaudanum's full-sized avatar

Frédéric Laudarin flaudanum

  • 365Talents
  • Lyon, France
View GitHub Profile
@flaudanum
flaudanum / MANIFEST.in
Last active November 23, 2020 23:50
Basic setup.py example for setuptools
prune Tests
graft Licenses
exclude pytest.ini README.md
@flaudanum
flaudanum / toolchains.xml
Created September 23, 2020 20:47
Apache Maven toolchains config with JDK 8, 11 and 14
<?xml version="1.0" encoding="UTF8"?>
<toolchains>
<toolchain>
<type>jdk</type>
<provides>
<version>1.8</version>
<vendor>Oracle</vendor>
</provides>
<configuration>
<jdkHome>C:\Program Files\Java\jdk1.8.0_241\</jdkHome>
@flaudanum
flaudanum / my_module.py
Created May 11, 2020 15:16
Stubbing file stream readlines method from Path().open with context manager
from pathlib import Path
def tested_function(path_obj: Path):
# fobj is the return value of path_obj.open().__enter__()
with path_obj.open('r') as fobj:
for line in fobj.readlines():
# do stuffs w/ line
@flaudanum
flaudanum / launch.json
Last active April 24, 2020 15:31
VS code config: Node.js, debug with auto-restart on code change provided by nodemon, run normal process in parallel
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"skipFiles": [
"<node_internals>/**"
],
@flaudanum
flaudanum / CmdProcUtils.java
Last active March 11, 2020 16:21
Utility static functions for running an external command as a sub-process
package com.my.domain;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
/**
* Static methods for running external command sub-processes
*/
public class CmdProcUtils {
@flaudanum
flaudanum / remove_ending_backslash_winpath.java
Created March 11, 2020 14:42
Remove ending backslash and trailing space from a Windows path
String winPath = "C:\\Users\\f.laudanum\\Documents\\My-Directory\\ ";
String cleanPath;
/* REGEXP pattern: '\\\s*' with doubled backslashes */
Pattern pattern = Pattern.compile("\\\\\\s*$");
Matcher match = pattern.matcher(winPath);
/* Call to find(0) triggers the pattern search from text's start*/
if (match.find(0)) {
cleanPath = match.replaceAll("");
@flaudanum
flaudanum / mockito_void_method.java
Created March 9, 2020 16:40
Mockito: mock a void method to do nothing
BackendRunner mockedRunner = mock(BackendRunner.class);
// Mock method runProcess() to do nothing
doAnswer(new Answer<Void>() {
public Void answer(InvocationOnMock invocation) {
Object[] args = invocation.getArguments();
System.out.println("called with arguments: " + Arrays.toString(args));
return null;
}
}).when(mockedRunner).runProcess(any());
@flaudanum
flaudanum / _README.md
Last active November 24, 2019 22:11
Apache Spark - PySpark snippets - Basic usage of class pyspark.RDD

PySpark examples

This gist is a collection of small scripts illustrating the basic usage of Apache Spark with the python API PySpark. I wrote them while reading the book Learning Spark from H. Karau, et al. (O'Reilly, 2015). The scripts are named after the examples in the book, although their content is merely inspired by the topics of the examples.

@flaudanum
flaudanum / ButtonExample.java
Last active February 3, 2020 16:35
Some basic javax.swing examples from javatpoint.com
package com.javatpoint;
import java.awt.event.*;
import javax.swing.*;
public class ButtonExample {
public static void main(String[] args) {
/* New frame with title 'Button Example' */
JFrame f = new JFrame("Button Example");
@flaudanum
flaudanum / nginx_server_block.conf
Created September 12, 2019 11:56
NginX - Location with a root that differs from the default one
server {
# Listening to port 80 (default port for HTTP protocol)
listen 80 default_server;
listen [::]:80 default_server;
# Default local root path for web resources
root /var/www/html;
# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html;