Skip to content

Instantly share code, notes, and snippets.

View pomber's full-sized avatar
🧭
Building @code-hike

Rodrigo Pombo pomber

🧭
Building @code-hike
View GitHub Profile
@pomber
pomber / hello_world.py
Created October 7, 2018 21:52
Hello World Examples
class HelloWorld:
def __init__(self, name):
self.name = name.capitalize()
def sayHi(self):
print "Hello " + self.name + "!"
hello = HelloWorld("world")
hello.sayHi()
@pomber
pomber / hello_world.py
Created October 7, 2018 21:51
Hello World Examples
class HelloWorld:
def __init__(self, name):
self.name = name.capitalize()
def sayHi(self):
print "Hello " + self.name + "!"
hello = HelloWorld("world")
hello.sayHi()
import React from 'react';
export default () => <div/>
@pomber
pomber / styled-components-snippets.jsx
Created September 28, 2018 15:22
Styled Components API snippets
const Title = styled.h1`
font-size: 1.5em;
text-align: center;
color: palevioletred;
:hover {
color: red;
}
`;
// attrs, props, &
let rootInstance = null;
function render(element, container) {
const prevInstance = rootInstance;
const nextInstance = reconcile(container, prevInstance, element);
rootInstance = nextInstance;
}
function reconcile(parentDom, instance, element) {
if (instance == null) {
import R from "ramda";
var divisibleBy = R.curry(R.pipe(R.flip(R.modulo), R.equals(0)));
var fizzbuzz = R.map(
R.cond([
[R.both(divisibleBy(3), divisibleBy(5)), R.always("FizzBuzz")],
[divisibleBy(3), R.always("Fizz")],
[divisibleBy(5), R.always("Buzz")],
[R.T, R.identity]
])
);
var FizzBuzz = (
<map>
<cond concat>
<pair>
<both>
<DivisibleBy value={3} />
<DivisibleBy value={5} />
</both>
<always value="FizzBuzz" />
</pair>
/** @jsx run */
function run(f, props, ...args) {
return R[f](...args);
}
var divisibleBy = (
<curry>
<pipe>
<flip>
<modulo />
const Hypotenuse = ({ values }) => (
<Sqrt>
<Sum>{values.map(v => <Pow exponent={2}>{v}</Pow>)}</Sum>
</Sqrt>
);
console.log(<Hypotenuse values={[3, 4, 5]} />);
const Sum = (...args) => args.reduce((a, b) => a + b, 0);
const Pow = ({ exponent }, base) => Math.pow(base, exponent);
const Sqrt = x => Math.sqrt(x);
const Hypotenuse = ({ a, b }) => (
<Sqrt>
<Sum>
<Pow exponent={2}>{a}</Pow>
<Pow exponent={2}>{b}</Pow>
</Sum>