Skip to content

Instantly share code, notes, and snippets.

View michalczaplinski's full-sized avatar
🏄‍♂️

Michal michalczaplinski

🏄‍♂️
View GitHub Profile
#!/usr/bin/env python
'''
Usage:
python cnm.py <input_file> <output_file>
'''
import heapq
import sys
import time
data <- read.csv(
"https://docs.google.com/spreadsheets/d/1rz8NGk05zQMpwK_DzSaxxBGnBrcyfzs5kjeraYwbJGY/export?format=csv&gid=326936124"
)
df <- data.frame(
date = as.Date(data$date),
ocurrencia = data$ocurrencia,
contingencia = data$contingencia,
fase = 0,
average = 0
)
<script>
import { store } from "@wordpress/interactivity";
store({
actions: {
toggle: ({ context }) => context.isOpen = !context.isOpen,
},
});
</script>
<button id="toggle-button">Toggle Element</button>
<p>This element is now visible!</p>
<script>
const button = document.getElementById("toggle-button");
button.addEventListener("click", () => {
const element = document.getElementById("element");
if (element) {
element.remove();
} else {
@michalczaplinski
michalczaplinski / rebase.fish
Created October 7, 2021 01:01
Rebase flow for Gutenberg
#!/usr/local/bin/fish
function rbase
set STASH_NAME (date +"%Y-%m-%d--%H:%M:%S")
set CURR_BRANCH (git rev-parse --abbrev-ref HEAD)
## Fetch from all remotes
git fetch --all
let boardState = [0, 0, 0, 0, 0, 0, 0, 0, 0];
// 1 is X
// 2 is O
const winningIndices = [
[0, 1, 2],
[3, 4, 5],
[6, 7, 8],
[0, 3, 6],
@michalczaplinski
michalczaplinski / useLoading.js
Created April 7, 2019 21:23
use loading hook
export default function useLoading() {
const [loadingState, setLoadingState] = React.useState({
isLoading: true,
hasError: false
});
const loadPromise = aPromise => {
setLoadingState({ isLoading: true, hasError: false });
return aPromise
.then((...args) => {
@michalczaplinski
michalczaplinski / flatten.js
Created January 23, 2019 21:39
Flatten arbitrarily nested arrays
function flatten(arr) {
// We could also always return an empty array if the arr argument is not an array
// That might or might not be what we want.
if (!Array.isArray(arr)) {
throw new TypeError(`The argument arr is not an Array!`);
}
let result = [];
for (let i = 0; i < arr.length; i++) {
const element = arr[i];
@michalczaplinski
michalczaplinski / search.sh
Created February 13, 2018 19:38
Find a file that existed at any point in a git repo
for branch in `git for-each-ref --format="%(refname)" refs/heads`; do
echo $branch :; git ls-tree -r --name-only $branch | grep '<foo>'
done
@michalczaplinski
michalczaplinski / index.js
Last active February 13, 2018 19:49
_.range() in pure JS
const array = (len) => Array(len).fill().map((e, i) => (i));
/*
* > console.log(array(3));
* > [0,1,2]
*
*/