Skip to content

Instantly share code, notes, and snippets.

View itszero's full-sized avatar

Zero Cho itszero

View GitHub Profile
@itszero
itszero / gist:5543218
Created May 8, 2013 20:04
Scala tutorial question
/* render a tweet using entities: for example
* val e = Entity(10, 21, """<a href="https://twitter.com/search/?q=%23ScalaIntro">#ScalaIntro</a>""")
* val entitites = Set(e)
* render("I love my #ScalaIntro exercises!", entities)
* should result in
* """I love my <a href="https://twitter.com/search/?q=%23ScalaIntro">#ScalaIntro</a> exercises!"""
* The "start" and "end" fields of an Entity refer to the indices in the
* original string to be substituted with the html field; you may assume
* that these indices are all non-overlapping.
*/
// 2.1 Implement buildCar in parallel (orders in parallel)
def buildCarPar(): Future[Car] = Future.join(
Factory.newChassis(),
Factory.newWheels(),
Future.join(
Factory.newCylinder(),
Factory.newPiston()
) flatMap { case (cylinder, piston) => buildEngine(cylinder, piston) }
) map { case (chassis, wheels, engine) => Car(chassis, wheels, engine) }
@itszero
itszero / main.rb
Last active August 29, 2015 13:56 — forked from josephcc/main.rb
steps = 5
(1..steps)
.map { |x| (1..steps-1).map { |y| [x, y] } }
.flatten(1)
.select { |x, y| steps - x - y > 0 }
.group_by { |x, y| x }
.each do |x, sets|
sets.each do |x, y|
puts [x, y].inspect
import React, { PropTypes } from 'react';
import ReactDOM from 'react-dom';
import d3 from 'd3';
import styles from './styles.css';
function getDefaultRange(axis, props) {
switch (axis) {
case 'x':
return [0, props.width];
@itszero
itszero / index.tsx
Last active October 26, 2018 17:20
Attempt to recreate react-redux using hooks
import * as React from "react";
import { useContext, useEffect, useState } from "react";
import { render } from "react-dom";
import { applyMiddleware, bindActionCreators, createStore } from "redux";
import ReduxThunk from "redux-thunk";
import { createSelector, createStructuredSelector } from "reselect";
import { action, getType } from "typesafe-actions";
interface Post {
id: number;