Skip to content

Instantly share code, notes, and snippets.

View itszero's full-sized avatar

Zero Cho itszero

View GitHub Profile
@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;
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 / 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
// 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 / 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.
*/
@itszero
itszero / fetch.sh
Created June 27, 2012 07:23
iTunes TW Feed List
#!/bin/sh
wget -O xml/top_albums.xml http://itunes.apple.com/tw/rss/topalbums/limit=300/explicit=true/xml
wget -O xml/new_releases.xml http://itunes.apple.com/WebObjects/MZStore.woa/wpa/MRSS/newreleases/sf=143470/limit=300/rss.xml
wget -O xml/just_added.xml http://itunes.apple.com/WebObjects/MZStore.woa/wpa/MRSS/justadded/sf=143470/limit=300/rss.xml
wget -O xml/featured_albums.xml http://itunes.apple.com/WebObjects/MZStore.woa/wpa/MRSS/featuredalbums/sf=143470/limit=300/rss.xml
@itszero
itszero / kb-ipad.html
Created May 14, 2011 11:44
CSS iPhone Keyboard Clone
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<title>Keyboard</title>
<style type="text/css">
#keyboard {
background-image: -webkit-gradient(linear, 0% 0%, 0% 100%, color-stop(0%, #9199A4), color-stop(50%, #7D8591), color-stop(100%, #535C69));
border-radius: 10px;
background-color: #9199A4;
old_gem = "gem"
new_gem = "/opt/ruby-enterprise/bin/gem"
oldgems = `#{old_gem} list`
# oldgems.each block written by spiceee.
# http://snippets.dzone.com/posts/show/6372
oldgems.each do |line|
newgems = `#{new_gem} list`
matches = line.match(/([A-Z].+) \(([0-9\., ]+)\)/i)
if matches
/* ../public_src/BookChooserController.j */
"封面" = "封面"
"標題" = "標題"
"修改時間" = "修改時間"
"繼續編輯" = "繼續編輯"
"取消" = "取消"
"選擇書本" = "選擇書本"
"載入中..." = "載入中..."
rvm install 1.9.1 # 不要用 1.9.2,會有很多問題 :P
wget http://sourceforge.net/projects/rubycocoa/files/RubyCocoa/1.0.1/RubyCocoa-1.0.1.tar.gz/download
tar zxvf RubyCocoa-1.0.1.tar.gz
cd RubyCocoa-1.0.1
ruby install.rb config
ruby install.rb setup
sudo ruby install.rb install # 會安裝像 Xcode Template 等東西,需要 root 權限