Skip to content

Instantly share code, notes, and snippets.

View raphaeljolivet's full-sized avatar

Raphael Jolivet raphaeljolivet

View GitHub Profile
@raphaeljolivet
raphaeljolivet / api.py
Created November 15, 2023 16:48
Add custom rest API to streamlit app
# This code adds custom REST api handler at runtime to a running Streamlit app
#
from tornado.web import Application, RequestHandler
from tornado.routing import Rule, PathMatches
import gc
import streamlit as st
@st.cache_resource()
@raphaeljolivet
raphaeljolivet / ExceptionContext.py
Created January 20, 2022 10:04
ExceptionContext : adding context to exceptions with "with" statement
from contextlib import AbstractContextManager
from future.utils import raise_from
class ExceptionContext(AbstractContextManager) :
def __init__(self, context):
self.context = context
def __exit__(self, exc_type, exc_val, exc_tb):
if exc_val != None :
@raphaeljolivet
raphaeljolivet / invite-all-friends-on-page.js
Last active August 3, 2017 19:59
Bookmarklet pour Facebook, pour inviter tous ses amis à une page.
javascript:(function(){
var click = function(e){e.click()};
var nbInvite = 0;
var exec = function() {
var invites = document.querySelectorAll("button[type='submit'][class*='_qfo']");
nbInvite += invites.length;
[].forEach.call(invites, click);
alert("Termine : " + nbInvite + " personnes invitees");
};
exec();
javascript:(function(){
var click = function(e){e.click()};
var nbInvite = 0;
var exec = function() {
var invites = document.querySelectorAll("button[type='submit'][class*='_qfo']");
nbInvite += invites.length;
[].forEach.call(invites, click);
};
exec();
})();
@raphaeljolivet
raphaeljolivet / invite-all.js
Last active May 24, 2018 22:56
Bookmarklet pour inviter à une page toutes les personnes ayant "liké" une publication.
javascript:(function(){
var click = function(e){e.click()};
var nbInvite = 0;
var exec = function() {
var invites = document.evaluate("a[contains('Invit')]", document, null, XPathResult.ANY_TYPE, null);
var invite
nbInvite += 1;
while ((invite = invites.iterateNext()) != null) {
invite.click();
nbInvite += 1;
@raphaeljolivet
raphaeljolivet / AutoMockTestRunner.java
Last active December 19, 2015 06:09
Junit Test Runner that automagically stubs Spring's @Autowired fields (setters) with Mockito mockups.
/**
* Smart JunitRunner that autowires fields together for @Autowire (Spring) fields,
* or create empty mock otherwize.
* The properties marked with @AutoMock will be autwired with other properties
* marked with @AutoMock or new empty mock.
*/
public class AutoMockTestRunner extends BlockJUnit4ClassRunner {
@Retention(RUNTIME)
@Target(FIELD)