Skip to content

Instantly share code, notes, and snippets.

@teaualune
teaualune / LinkedList.swift
Created October 31, 2018 06:37
Basic one-way linked list implementation example in Swift 4
/*
* definition
*/
indirect enum LinkedList<T> : Sequence {
case end
case node(value: T, next: LinkedList<T>)
init() {
self = .end
@teaualune
teaualune / fanout.go
Created May 24, 2018 03:03
Minimal fanout pattern implemented with goroutine
package main
import (
"context"
"sync"
)
// FanOutContext contains fanout data
type FanOutContext struct {
channels []chan interface{}
@teaualune
teaualune / _README.md
Last active November 12, 2016 18:20
An alternative routing example for React.js

This is a small example to build a simple routing solution for React.js instead of using the popular React Router.

It utilizes great libraries e.g. history and universal-router which are React-independent.

The example includes:

  • A singleton history object for URL navigation
  • A Router component to route different child components
  • A Link component that acts as those in React Router or in React Static Boilerplate
  • An example component App to demostrate their usages
/*
* CJK Regex brought from http://apps.timwhitlock.info/js/regex
*/
var CJKRegex = /[⺀-\u2efe\u3000-〾\u3040-ゞ゠-ヾ㇀-\u31eeㇰ-ㇾ㈀-㋾㌀-㏾㐀-\u4dbe一-\u9ffe豈-\ufafe︰-﹎]|[\ud840-\ud868\ud86a-\ud86c][\udc00-\udfff]|\ud82c[\udc00-\udcfe]|\ud869[\udc00-\udede\udf00-\udfff]|\ud86d[\udc00-\udf3e\udf40-\udfff]|\ud86e[\udc00-\udc1e]|\ud87e[\udc00-\ude1e]/;
/*
* Normalize display name for both Chinese and English names.
* @function
* @param {string} firstName
@teaualune
teaualune / question_angular.js
Last active June 15, 2016 07:49
JS Interview Questions
/*
* The following code snippet runs in an angular controller body.
* It tries to convert a blob object "data" into data URL and bind the result to the scope.
* Fix it so that $scope.data will make UI change as expected.
*/
/* global angular, data, FileReader */
angular.module('xxx').controller('Ctrl', ['$scope', function ($scope) {
var reader = new FileReader();
# 宣告變數
if 1:
import random
EmptyBoard = [[0,0,0,0,0,0],[0,0,0,0,0,0],[0,0,0,0,0,0],[0,0,0,0,0,0],[0,0,0,0,0,0]]
Board = [[1, 2, 2, 2, 1, 1], [1, 2, 1, 2, 2, 2], [1, 2, 2, 1, 1, 1], [1, 1, 1, 1, 1, 1], [1, 1, 2, 1, 2, 2]]
CancelBoard = EmptyBoard
Comboing = 0
Comboed =0
@teaualune
teaualune / gist:9212728
Created February 25, 2014 16:44
jQuery event binding in array
var tableArr = [
"<p>line 1</p>",
"<p>line 2</p>",
"<p>line 3</p>"
],
key = 0;
for (key; key < tableArr.length; key = key + 1) {
(function (k) {
$('#line' + k).click(function (event) {
X = [94.66 6.89 64.06 27.13 0.128356534 1770.99 10.96; ...
93.79 3.76 81.33 14.34 0.136729489 1509.71 25.79; ...
93.45 9.95 87.66 29.68 0.608227884 1425.85 45.61; ...
95.81 9.16 104.47 20.81 0.689591432 2285.79 22.86; ...
72.71 14.75 67.74 10.55 0.067760754 266.42 50.21; ...
94.11 11.92 74.25 14.17 0.172147321 1597.82 28.82; ...
81.19 4.14 84.28 15.67 0.085490275 431.63 28.65; ...
92.49 8.45 87.3 18.24 0.125981923 1232.12 44.27; ...
93.15 3.43 83.96 12.99 0.155595884 1360.22 37.87; ...
95.64 8.36 115.84 10.71 0.675068648 2195.31 24.09; ...
X = [20.5156 12.0474 -12.1288 7.4995 38.9435 -4.5757 20.6246 19.6316 -7.3335 -2.6384 9.1368 24.2808 14.8241 15.9592 5.9249 19.085 -13.4054 -3.3012];
Y = [4 5 5 3 2 3 5 2 3 2 5 4 4 1 6 6 6 6];
[B, dev, stats] = mnrfit(X,Y, 'model', 'ordinal', 'interactions', 'off');
% output:
% B =
%
% -3.3364
% -1.6701
% -0.8469
<html>
<head>
<link rel="stylesheet" href="http://yui.yahooapis.com/pure/0.2.1/grids-min.css">
</head>
<body>
<div class="pure-g">
<div class="pure-u-1-3"><p>Thirds</p></div>
<div class="pure-u-1-3"><p>Thirds</p></div>
<div class="pure-u-1-3"><p>Thirds</p></div>
</div>