Skip to content

Instantly share code, notes, and snippets.

View jpsierens's full-sized avatar
🙃

Jean-Pierre Sierens jpsierens

🙃
View GitHub Profile
// Create the context for user related data
export const UserContext = React.createContext();
const user = {
name: 'Jean-Pierre',
sex: 'Yes'
}
// provider the user context anywhere in the app
function App() {
@jpsierens
jpsierens / scheme-sqrt.sc
Created December 2, 2017 01:33
scheme-sqrt created by philander - https://repl.it/@philander/scheme-sqrt
; Now let’s formalize the process in terms of procedures. We start with a value for the radicand (the number whose square root we are trying to compute) and a value for the guess. If the guess is good enough for our purposes, we are done; if not, we must repeat the process with an improved guess. We write this basic strategy as a procedure: (define (improve guess x) (average guess (/ x guess))) (define (average x y) (/ (+ x y) 2)) (define (square x) (* x x)) (define (good-enough? guess x) (< (abs (- (square guess) x)) 0.001)) (define (sqrt-iter guess x) (if (good-enough? guess x) ; return guess guess ; otherwise (sqrt-iter (improve guess x) x ))) (define (sqrt x) (sqrt-iter 1.0 x)) (sqrt 9)
@jpsierens
jpsierens / imageFit.js
Last active August 29, 2015 14:10
Fit an image to its direct container by rescaling each time the window resizes.
function imageFit (img) {
$(img)
.attr('startwidth', $(img).width())
.attr('startheight', $(img).height());
//add 100% width to the container, so that the image stretches above its max width.
.parent().css('width','100%');
//initial fit
fit();
// Re-adjust when window width is changed