Skip to content

Instantly share code, notes, and snippets.

View rafaelrinaldi's full-sized avatar

Rafael Rinaldi rafaelrinaldi

View GitHub Profile
(ns private.tmp.units)
(defn- ounces->kg
[input]
(let [lb 16 ;; 1kg → 16lb
oz 2.2] ;; 1kg → 2.2oz
(->> (/ input lb oz) (format "%.3f kg"))))
.toggle {
cursor: pointer;
user-select: none;
display: flex;
align-items: center;
justify-content: left;
}
.toggle-phony {
opacity: 0;
@rafaelrinaldi
rafaelrinaldi / core.clj
Created July 7, 2017 02:27
Upload a JSON file to an S3 bucket
(ns facebook-campaigns-resolver.core
(:require [cheshire.core :as json]
[clj-http.client :as http]
[amazonica.aws.s3 :as s3]
[amazonica.aws.s3transfer :as s3transfer]
[clojure.java.io :as io]))
(def ^:private url "https://jsonplaceholder.typicode.com/comments?postId=1")
(def ^:private aws {:key ""

>! and `

@rafaelrinaldi
rafaelrinaldi / Visibility.js
Created April 12, 2017 23:54
Simple functional stateless component to make component rendering declarative and avoid JSX evaluation magic.
import { Children, PropTypes } from 'react';
const Visibility = ({ visible, children }) => (
visible ? Children.only(children) : null
);
Visibility.defaultProps = {
visible: true,
};
/**
* Simple script that compares our npm manifest against Oscar's manifest
* and list all results that don't match versions.
*
* Usage:
*
* node tools/diff-package-json.js path/to/oscar/package.json
**/
const current = require('../package');
# This script will take care of react-specific imports just so
# Preact can do its job (production only)
modules=./node_modules
bin=$modules/.bin
replace=$bin/replace
pattern="require\('react\/lib\/ReactDOMFactories'\)"
target=$modules/remarkable-react/lib/lib/renderer.js
if [ ! -d "$modules" ]; then
const MATCH_MARKDOWN_IMAGE = /\!\[(.*)\]\((.*)\)/gm;
const MATCH_INLINE_IMAGE = /\(inline\)/i;
class MarkdownImage {
// We receive both `markdown` and `containerWidth` on the constructor here
static updateImageTags(markdown) {
let updatedMarkdown = markdown;
let match;
let matches = [];
@rafaelrinaldi
rafaelrinaldi / component.js
Last active March 6, 2017 16:06
Handy component base class for CSS in JS projects
import Preact from 'preact'
import { StyleSheet, css } from 'aphrodite/no-important'
class Component extends Preact.Component {
constructor () {
super()
this._rawStyles = this.styles ? this.styles() : {}
this._styles = StyleSheet.create(this._rawStyles)
this._parseClassNames = this._parseClassNames.bind(this)
// Polyfills
import 'promise-polyfill';
import 'whatwg-fetch';
import React from 'react';
import { render } from 'react-dom';
import { Provider } from 'react-redux';
import { Redirect, Router, Route, IndexRoute, browserHistory } from 'react-router';
import configureStore from './store/configureStore';