Skip to content

Instantly share code, notes, and snippets.

@palutz
palutz / app.js
Last active January 27, 2016 18:11
Eris web app for contract with bytes type data
// requires
var fs = require ('fs');
var prompt = require('prompt');
var erisC = require('eris-contracts');
var conv = require('binstring');
// NOTE. On Windows/OSX do not use localhost. find the
// url of your chain with:
// docer-machine ls
// and find the docker machine name you are using (usually default or eris).
@palutz
palutz / twoCollections.scala
Last active March 24, 2017 14:20
Check which strings are in a List[String] from another List[String]
val newspaper = List("a1", "a2", "b11", "a2", "aa", "a2", "aa", "a2", "aa")
val note = List("a1", "a2", "b11", "a2", "aa")
val mw = for { // using for comprehension
n <- newspaper
r <- note
if r == n
} yield r -> 1 // mapped words - getting a List[(String, Int)]
val mw2 = newspaper.flatMap(n =>
@palutz
palutz / Functional clash - recursive sum
Last active June 20, 2017 09:11
Haskell vs Scala vs F# - A recursive sum
# recursive sum
### Haskell
mysum [] = 0
mysum (x:xs) = x + mysum xs
Usage:
mysum [1..10] // 55
### Scala
@palutz
palutz / Functional clash - simple quicksort
Created June 20, 2017 09:11
Haskell vs Scala vs F# - Quicksort
myqs [] = []
myqs (x:xs) = myqs lessthan ++ [x] ++ myqs greaterthan
where
lessthan = [a | a <- xs, a <= x ]
greaterthan = [b | b <- xs, b > x]
### Scala implementation
def mysq (l : List[Int]) : List[Int] =
l match {
@palutz
palutz / Reactprops.js
Last active August 11, 2017 16:57
playing with React components
//Greeting.js
import React from 'react';
// use export to let other files access this component
export class Greeting extends React.Component {
render() {
return <h1>Hi there, {this.props.name}!</h1>;
}
}
// App.js
import React from 'react';
import ReactDOM from 'react-dom';
class Button extends React.Component {
render() {
return (
<button>
{this.props.text}
</button>
);
import React from 'react';
import ReactDOM from 'react-dom';
const green = '#39D1B4';
const yellow = '#FFD712';
class Toggle extends React.Component {
constructor(props) {
super(props);
this.state = { color: green };
//
// Child.jsx
//
import React from 'react';
export class Child extends React.Component {
constructor(props) {
super(props);
this.handleChange = this.handleChange.bind(this);
}
// AKA React Patterns
// A stateful component class defines a function that calls this.setState. (Parent, lines 15-19)
//The stateful component passes that function down to a stateless component. (Parent, line 24)
// That stateless component class defines a function that calls the passed-down function, and that can take an event object as an argument. (Child, lines 10-13)
// The stateless component class uses this new function as an event handler. (Child, line 20)
// When an event is detected, the parent's state updates. (A user selects a new dropdown menu item)
//The stateful component class passes down its state, distinct from the ability to change its state, to a different stateless component. (Parent, line 25)
//That stateless component class receives the state and displays it. (Sibling, lines 5-10)
//An instance of the stateful component class is rendered. One stateless child component displays the state, and a different stateless child component displays a way to change the (Parent, lines 23-26)
Verifying that "stefanop.id" is my Blockstack ID. https://onename.com/stefanop