Skip to content

Instantly share code, notes, and snippets.

View jeromepl's full-sized avatar

Jérôme Parent-Lévesque jeromepl

View GitHub Profile
@jeromepl
jeromepl / raked_weighting.py
Last active January 24, 2024 14:48
Raked Weighting in Python
import numpy as np
def raking_inverse(x):
return np.exp(x)
def d_raking_inverse(x):
return np.exp(x)
def graking(X, T, max_steps=500, tolerance=1e-6):
# Based on algo in (Deville et al., 1992) explained in detail on page 37 in
@jeromepl
jeromepl / mark_as_ready_for_review.sh
Last active April 1, 2022 15:05
Mark as "Ready for review" and assign reviewers on GitHub pull requests after test suite passes
#!/bin/bash
set -eou pipefail
# This script was partially inspired by https://arturdryomov.dev/posts/auto-github-pull-requests/
# Few notes about some of the decisions that led to the code below:
# - The GitHub REST API does not support the marking PRs as ready for review.
# Instead, this has to be done through the GraphQL API, **and** requires a
# personal access token since the Github Action default token cannot have
# the required permission
# - It would have been cleaner to split up all the queries in this file as
@jeromepl
jeromepl / raked_weighting.rb
Created August 10, 2021 16:30
Raked Weighting in Ruby
require "numo/narray"
require "numo/linalg"
def raking_inverse(x)
Numo::NMath.exp(x)
end
def d_raking_inverse(x)
Numo::NMath.exp(x)
end
@jeromepl
jeromepl / Enhance.js
Last active April 6, 2020 20:26 — forked from sebmarkbage/Enhance.js
Higher-order Components in React with ES7
import { Component } from "React";
export default (ComposedComponent) => class extends Component {
constructor(props) {
super(props);
this.state = { data: null };
}
componentDidMount() {
this.setState({ data: 'Hello' });
}
@jeromepl
jeromepl / getQuery-plugin.js
Last active September 18, 2017 23:35
Get a CSS-style query to a DOM element. (With JQuery)
// Same as the other file, but this time as a JQuery plugin.
// Usage: $(someElement).getQuery();
(function ($) {
$.fn.getQuery = function() {
var id = this.attr('id');
var localName = this.prop('localName');
if (id)
return '#' + escapeCSSString(id);
@jeromepl
jeromepl / debounceGroup.js
Last active July 17, 2017 18:49
Debouncer that keeps the last N calls active
// Keep the last N calls active
// A regular debounce function would only keep a single function call
// on timeout at a time.
function debounceGroup(func, wait, groupSize) {
var timeouts = []; // Use this array as a queue of method calls
return function() {
var context = this,
args = Array.prototype.slice.call(arguments, 0);
if (timeouts.length >= groupSize)
clearTimeout(timeouts.shift());