Skip to content

Instantly share code, notes, and snippets.

View namelos's full-sized avatar
💤
zzz

Yifan Wang namelos

💤
zzz
View GitHub Profile
@namelos
namelos / gen_task.ex
Last active May 1, 2018 01:20
Generic task
defmodule GenTask do
def async do
parent = self()
spawn(fn ->
receive do
{:resolve, value} -> send parent, {self(), :result, value}
{:reject, reason} -> send parent, {self(), :reject, reason}
end
end)
const React = require('react')
const ReactDOM = require('react-dom/server')
const express = require('express')
const app = express()
const html = content => `
<!doctype html>
<html>
<body>
@namelos
namelos / upgrade.md
Last active March 14, 2017 14:02 — forked from chrismccord/upgrade.md
Phoenix 1.2.x to 1.3.0 Upgrade Instructions

If you want a run-down of the 1.3 changes and the design decisions behidn those changes, check out the LonestarElixir Phoenix 1.3 keynote: https://www.youtube.com/watch?v=tMO28ar0lW8

To use the new phx.new project generator, you can install the archive with the following command:

$ mix archive.install https://github.com/phoenixframework/archives/raw/master/phx_new.ez

Bump your phoenix dep

Phoenix v1.3.0 is a backwards compatible release with v1.2.x. To upgrade your existing 1.2.x project, simply bump your phoenix dependency in mix.exs:

;; -*- mode: emacs-lisp -*-
;; This file is loaded by Spacemacs at startup.
;; It must be stored in your home directory.
(defun dotspacemacs/layers ()
"Configuration Layers declaration.
You should not put any user code in this function besides modifying the variable
values."
(setq-default
;; Base distribution to use. This is a layer contained in the directory
const Subject = require('rxjs').Subject
const run = require('@cycle/rxjs-run').run
const http = require('http')
const makeServerDriver = port => {
const requests$ = new Subject()
http.createServer((req, res) => requests$.next({ req, res }))
.listen(port, _ => console.log(`listening on ${port}`))
const http = require('http')
const Rx = require('rxjs')
const main = ({ HTTP }) => ({
HTTP: HTTP.map(req => `Hello ${req.url}`)
})
const makeHttpEffect = _ => {
const requests$ = new Rx.Subject()
class Maybe {
constructor(x) {
this.__value = x
}
static of(x) {
return new Maybe(x)
}
isNothing() {
class Program
{
static void Main(string[] args)
{
Func<int, Func<int, Func<int, int>>> add = x => y => z => x + y + z;
WriteLine(add(1)(2)(3));
Func<Func<int>> Closure = () =>
{
@namelos
namelos / cycle-server.js
Created May 21, 2016 14:13
cycle server
const http = require('http')
const Cycle = require('@cycle/core')
const Rx = require('rx')
const makeServerDriver = port => {
const server$ = new Rx.Subject()
return sink$ => {
http.createServer((request, response) => {
server$.onNext({ request, response })
type Input<InputType, Validator> = {
value: InputType
default: InputType
description: Description
validation: Validator
}
type InputType = (TextField | TextArea | CheckBox | CheckGroup<CheckBox> | Radio | Select)
type Description = string