Skip to content

Instantly share code, notes, and snippets.

@pe3
pe3 / deno-fp-ts-log.ts
Last active April 24, 2021 14:36
Deno fp-ts Hello world
import { log } from "https://cdn.skypack.dev/fp-ts/Console";
log("hello world!")();
// deno run deno-fp-ts-log.ts
// evaluating tree shaking and maximum compability bundles
// see ts-doc for config options https://www.typescriptlang.org/tsconfig
// deno bundle --config tsconfig.json deno-fp-ts-log.ts log-bundle.js
// as of deno 1.9.1 the following options were ignored: module, target
@pe3
pe3 / fizzbuzz.js
Last active February 4, 2018 11:08
declarative javascript sollution to fizzbuzz
// It's more interesting if the numbers are -50 to +50.
const range = (x1,x2) => [...Array(x2-x1+1)].map( (_,i)=>x1+i )
const maybeFizz = x => x%3==0 ? 'fizz' : undefined
const maybeBuzz = x => x%5==0 ? 'buzz' : undefined
const join = (s1,s2) => [s1,s2].join('')
const maybeText = x => join(maybeFizz(x),maybeBuzz(x))
@pe3
pe3 / 0-Code verbosity vs expressiveness.md
Last active September 15, 2017 12:01
Simple fetch based API client implementations
@pe3
pe3 / index.js
Last active September 12, 2017 13:15
quite clean and minimal async http call
const r2 = require('r2')
// asynchronous arrow functions seem to need an explicit return to work properly
const loadUser = async id => { return await r2(`https://jsonplaceholder.typicode.com/users/${id}`).json }
(async function() {
console.log(await loadUser(2))
})()
@pe3
pe3 / index.js
Created May 22, 2017 11:06
Programmatically writing to Wikidata
const config = {
// Required
username: 'personal-wikidata-username',
password: 'password',
// Optional
verbose: true // Default: false
}
const wdEdit = require('wikidata-edit')(config)
@pe3
pe3 / README.md
Last active September 15, 2017 11:31
a bug in readr R module

The data is from the Finnish ministry of justice election results

curl -O http://tulospalvelu.vaalit.fi/K2012/data/k-2012_ehd_maa.csv.zip
unzip k-2012_ehd_maa.csv.zip
head -n 1 kv-2012_teat_maa.csv > scandinavian.csv
iconv -f ISO-8859-1 -t UTF-8  scandinavian.csv  > scandinavian-utf.csv
$ file -I scandinavian.csv 
scandinavian.csv: text/plain; charset=iso-8859-1
$ file -I scandinavian-utf.csv
import React, { PropTypes } from 'react'
import ReactDOM from 'react-dom'
import { createStore, combineReducers, applyMiddleware } from 'redux'
import { Provider, connect } from 'react-redux'
import sagaMiddleware, { take, put, fork } from 'redux-saga'
// React component
export class Counter extends React.Component {
render(){
const { value, clickPlus, clickMinus, clickSlow } = this.props
@pe3
pe3 / index.html
Created January 15, 2016 12:33
Simplest React dev boilerplate
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<script src="https://npmcdn.com/react@0.14.6/dist/react.js" charset="utf-8"></script>
<script src="https://npmcdn.com/react-dom@0.14.6/dist/react-dom.js" charset="utf-8"></script>
<script src="https://npmcdn.com/babel-core@5.8.34/browser-polyfill.min.js" charset="utf-8"></script>
<script src="https://npmcdn.com/babel-core@5.8.34/browser.min.js" charset="utf-8"></script>
</head>
@pe3
pe3 / fetchInComponent.js
Last active October 22, 2015 23:15
REST call in componentWillMount
import React from 'react'
import ReactDOM from 'react-dom'
import fetch from 'isomorphic-fetch'
const App = () => (
<div>
<RepositoryList id="pe3"/>
</div>
)
@pe3
pe3 / React-0.13-ES2015-SUIT-CSS.md
Last active August 29, 2015 14:15
React 0.13 ES2015 SUIT CSS

to run: webpack-dev-server

suit-loader is deprecated.

should probably use something like rework-webpack-loader but i dont understand webpack or rework well enough.