Skip to content

Instantly share code, notes, and snippets.

View leogout's full-sized avatar

Léo Richard leogout

  • France
View GitHub Profile
@TheGreatRambler
TheGreatRambler / szudzik.js
Last active February 10, 2024 20:23
A pairing function (szudzik) that supports negative numbers
// src https://codepen.io/sachmata/post/elegant-pairing
szudzik.getindex = function(x, y) {
var xx = x >= 0 ? x * 2 : x * -2 - 1;
var yy = y >= 0 ? y * 2 : y * -2 - 1;
return (xx >= yy) ? (xx * xx + xx + yy) : (yy * yy + xx);
};
szudzik.unpair = function(z) {
var sqrtz = Math.floor(Math.sqrt(z));
#!/bin/python
#
# Connects to a Wifi network
#
import os
def commandExists(command):
def canExecute(file):
return os.path.isfile(file) and os.access(file, os.X_OK)
@benpickles
benpickles / action.js
Created March 18, 2016 16:19
Inject an Authorization header into a redux-api-middleware request with a Redux middleware.
import { CALL_API } from 'redux-api-middleware'
export function fetchLocations() {
return {
[CALL_API]: {
endpoint: 'http://api.somesite.com/api/locations',
method: 'GET',
// Don't have to manually add the Authorization header to every request.
headers: { 'Content-Type': 'application/json' },
types: ['REQUEST', 'SUCCESS', 'FAILURE']