Skip to content

Instantly share code, notes, and snippets.

Avatar

Jérôme Parent-Lévesque jeromepl

View GitHub Profile
@jeromepl
jeromepl / mark_as_ready_for_review.sh
Last active Apr 1, 2022
Mark as "Ready for review" and assign reviewers on GitHub pull requests after test suite passes
View mark_as_ready_for_review.sh
#!/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 Aug 10, 2021
Raked Weighting in Ruby
View raked_weighting.rb
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 / raked_weighting.py
Last active Aug 10, 2021
Raked Weighting in Python
View raked_weighting.py
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 / getQuery-plugin.js
Last active Sep 18, 2017
Get a CSS-style query to a DOM element. (With JQuery)
View getQuery-plugin.js
// 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 Jul 17, 2017
Debouncer that keeps the last N calls active
View debounceGroup.js
// 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());
@jeromepl
jeromepl / Enhance.js
Last active Apr 6, 2020 — forked from sebmarkbage/Enhance.js
Higher-order Components in React with ES7
View Enhance.js
import { Component } from "React";
export default (ComposedComponent) => class extends Component {
constructor(props) {
super(props);
this.state = { data: null };
}
componentDidMount() {
this.setState({ data: 'Hello' });
}