Skip to content

Instantly share code, notes, and snippets.

View pozdneev's full-sized avatar

Alexander Pozdneev pozdneev

View GitHub Profile
@pozdneev
pozdneev / README.md
Last active March 5, 2023 16:21
Avoiding conflicts in git when merging a squashed commit from main into feature branch
@pozdneev
pozdneev / mem_fn.cpp
Created May 5, 2021 20:03
mem_fn: supplying template arguments
// g++ -std=c++14 -c mem_fn.cpp
#include <vector>
#include <functional>
#include <algorithm>
using namespace std;
struct A {
int& getAttribute();
const int& getAttribute() const;
@pozdneev
pozdneev / mem_fn.cpp
Created May 5, 2021 20:01
mem_fn: no match for call
// g++ -std=c++14 -c mem_fn.cpp
//
// /usr/include/c++/7/bits/stl_algo.h:4306:24:
// error: no match for call to ‘(std::_Mem_fn<int& (A::*)()>) (const A&)’
//
// /usr/include/c++/7/functional:174:27:
// error: no matching function for call to ‘__invoke(int& (A::* const&)(), const A&)’
//
// /usr/include/c++/7/bits/invoke.h:89:5:
// error: no type named ‘type’ in ‘struct std::__invoke_result<int& (A::* const&)(), const A&>’
@pozdneev
pozdneev / mem_fn.cpp
Created May 5, 2021 19:43
mem_fn: const-method only
// g++ -std=c++14 -c mem_fn.cpp
#include <vector>
#include <functional>
#include <algorithm>
using namespace std;
struct A {
const int& getAttribute() const;
};
@pozdneev
pozdneev / mem_fn.cpp
Last active May 5, 2021 20:02
mem_fn: unresolved overloaded function type
// g++ -std=c++14 -c mem_fn.cpp
//
// error: no matching function for call to ‘mem_fn(<unresolved overloaded function type>)’
#include <vector>
#include <functional>
#include <algorithm>
using namespace std;
struct A {
@pozdneev
pozdneev / README.md
Created June 4, 2020 16:40 — forked from bartdag/README.md
Py4J - Multiple GatewayServer and CallbackServer instances

Py4J Multiple GatewayServer and CallbackServer instances

Compile and run TestApplication.java with py4j.jar in your classpath.

Then execute python3 test.py

Explanations

This creates three pairs of GatewayServer and CallbackServer with different ports on both the Java and Python sides. Python is driving the communication by asking Java to print

@pozdneev
pozdneev / number_as_a_suffix.f90
Created April 23, 2018 09:22
Adding a number as a file name suffix
integer, save :: num_calls = 0
character(len=1024) :: file_suffix
num_calls = num_calls + 1
write (file_suffix, "(I5.5)") num_calls
open(37, file='prefix_' // trim(file_suffix) // '.bin', form='unformatted')
@pozdneev
pozdneev / uio.f90
Created April 21, 2018 09:11
(De)serialization of Fortran basic data types
program uio
real :: a(10), b(12)
a(:) = 1
b(:) = 2
open(37, file='uio.bin', form='unformatted')
write(37) a, b
close(37)
open(37, file='uio.bin', form='unformatted')
@pozdneev
pozdneev / IteratorRemove.java
Created January 23, 2018 13:57
How to remove an element from a collection while iterating over it
import java.util.Collection;
import java.util.Iterator;
import java.util.LinkedList;
public class IteratorRemove {
static public void main(String[] args) {
// Populate a collection
Collection<Integer> ll = new LinkedList<>();
for (int i = 0; i < 10; ++i) {
ll.add(i);
@pozdneev
pozdneev / SpeakingEnum.java
Created January 12, 2018 11:33
Demonstrates the String representation of a Java enum
public class SpeakingEnum {
public static enum SPEAKING_ENUM {
SOME_VALUE,
SOME_OTHER_VALUE;
public void speak() {
System.out.println("this=" + this);
}
}