Skip to content

Instantly share code, notes, and snippets.

View marccarre's full-sized avatar

Marc Carré marccarre

View GitHub Profile
@marccarre
marccarre / README.md
Last active October 26, 2023 20:47
Vagrant on Apple M1
View README.md

Vagrant on Apple M1

Summary:

  • QEMU: ✅ (but few boxes)
  • libvirt: ❎ (suggestions welcome!)
  • Parallels: ✅ (but few boxes)
  • VMWare Fusion: ✅ (but few boxes)
  • VirtualBox: ❎ (timeout)
@marccarre
marccarre / list_kindle_releases.py
Created October 24, 2020 08:46
List all available versions of Kindle for Mac and Kindle for PC.
View list_kindle_releases.py
#!/usr/bin/env python
'''
List all available versions of Kindle for Mac and Kindle for PC.
Dependencies:
- asyncio==3.4.3
- aiohttp==3.6.3
'''
import os
import sys
@marccarre
marccarre / leetcode-ranking.py
Last active July 19, 2020 06:24
leetcode-ranking.py
View leetcode-ranking.py
#!/usr/bin/env python
'''
Usage:
./leetcode-ranking.py -c 198 marccarre Hydromail daisuke834
2400 marccarre 96
2895 Hydromail 116
6666 daisuke834 267
Prerequisites:
- pipenv install click==7.1.2
@marccarre
marccarre / springer.py
Last active May 26, 2020 15:12
Download all open Springer ebooks
View springer.py
#!/usr/bin/env python
'''
Springer has released some ebooks freely in order to support learning during
these times of lockdown with the COVID-19 spreading.
Source: https://www.springernature.com/gp/librarians/news-events/all-news-articles/industry-news-initiatives/free-access-to-textbooks-for-institutions-affected-by-coronaviru/17855960
A spreadsheet containing the URLs of all available books can be found on the
aforementioned page. These URLs have been hardcoded below. And this script
lets you download all books automatically.
@marccarre
marccarre / heap.py
Created January 28, 2020 02:03
Min and max heaps in Python
View heap.py
from __future__ import annotations # To allow "MinHeap.push -> MinHeap:"
from typing import Generic, List, Optional, TypeVar
from heapq import heapify, heappop, heappush, heapreplace
T = TypeVar('T')
class MinHeap(Generic[T]):
'''
@marccarre
marccarre / keybase.md
Created March 25, 2017 09:23
keybase.md
View keybase.md

Keybase proof

I hereby claim:

  • I am marccarre on github.
  • I am marccarre (https://keybase.io/marccarre) on keybase.
  • I have a public key whose fingerprint is E783 6CDE 2E42 F8FE 3847 0FBF 0626 58EF F69B 8B32

To claim this, I am signing this object:

@marccarre
marccarre / AsynchronousLongComputeVsSlowStore.java
Last active July 19, 2016 20:55
Asynchronously compute or load from cache
View AsynchronousLongComputeVsSlowStore.java
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import static java.util.concurrent.TimeUnit.SECONDS;
public class AsynchronousLongComputeVsSlowStore {
private static final ConcurrentMap<Integer, Integer> store = new ConcurrentHashMap<>();
@marccarre
marccarre / AsynchronousSumAndMax.java
Last active May 19, 2016 03:53
Asynchronously synchronise and aggregate intermediate results
View AsynchronousSumAndMax.java
package com.marccarre;
import java.util.Arrays;
import java.util.Comparator;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.stream.Stream;
import static java.util.concurrent.CompletableFuture.completedFuture;
@marccarre
marccarre / AsynchronousExceptionsHandlingWithWhenComplete.java
Created May 15, 2016 12:53
Asynchronously handle and propagate the exception
View AsynchronousExceptionsHandlingWithWhenComplete.java
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
public class AsynchronousExceptionsHandlingWithWhenComplete {
public static void main(final String[] args) throws InterruptedException, ExecutionException {
for (final boolean failure : new boolean[]{false, true}) {
CompletableFuture<Integer> x = CompletableFuture.supplyAsync(() -> {
if (failure) {
throw new RuntimeException("Oops, something went wrong");
@marccarre
marccarre / AsynchronousExceptionsHandlingWithHandle.java
Created May 8, 2016 17:59
Asynchronously handle exception and return a transformed future
View AsynchronousExceptionsHandlingWithHandle.java
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import static java.lang.String.format;
public class AsynchronousExceptionsHandlingWithHandle {
public static void main(final String[] args) throws InterruptedException, ExecutionException {
for (final boolean failure : new boolean[]{false, true}) {
CompletableFuture<Integer> x = CompletableFuture.supplyAsync(() -> {
if (failure) {