Skip to content

Instantly share code, notes, and snippets.

View maowug's full-sized avatar
🏠
Working from whitehouse

u.go maowug

🏠
Working from whitehouse
View GitHub Profile
@maowug
maowug / futureValue.md
Created November 11, 2016 09:59
futureValue fails? with intercept

try

intercept[DBException] {
  categoryDAO.insert(catFixture).futureValue
  categoryDAO.insert(catFixture).futureValue
}
@maowug
maowug / anyDuplicate.scala
Created September 26, 2016 06:28
`withFilter` rocks when used as a flag & something like short circulating
def anyDuplicate(arr: List[Int], k: Int): Boolean = {
var any_duplicate = false
val hs = mutable.HashSet[(Int, Int)]()
arr.zipWithIndex
.withFilter(_ => !any_duplicate)
.map {
case tp @ (e, idx) =>
hs.find(_._1 == tp._1) match {
case Some((d, idxD)) if (tp._2 - idxD <= k) =>
any_duplicate = true // <-------- update flag
trait Encryption {
/**
* Encrypt token
* @param app
* @param token
* @return
*/
def encryptToken(app: Application, token: String): String = {
@maowug
maowug / listViewBasicsWithFetch.js
Created September 6, 2016 08:43
fetch, enableEmptySections ?
import React, { Component } from 'react';
import {
AppRegistry,
StyleSheet,
Text,
View,
Image,
TextInput,
AlertIOS,
@maowug
maowug / simpleTimer.scala
Created August 24, 2016 09:05
simple block timer
def time[R](name: String)(block: => R): R = {
val t0 = System.currentTimeMillis()
val result = block
val t1 = System.currentTimeMillis()
println(s" $name time: " + (t1 - t0) + "ns")
result
}
val Times = 1000000

Make it real

Ideas are cheap. Make a prototype, sketch a CLI session, draw a wireframe. Discuss around concrete examples, not hand-waving abstractions. Don't say you did something, provide a URL that proves it.

Ship it

Nothing is real until it's being used by a real user. This doesn't mean you make a prototype in the morning and blog about it in the evening. It means you find one person you believe your product will help and try to get them to use it.

Do it with style

@maowug
maowug / de-constructing.js
Created February 28, 2016 08:14
arguments de-constructing babel6
function isMessageAttributeValid ({DataType} = {}) {
console.log(arguments)
if (!DataType) {
// throw new Error('A MessageAttribute must have a DataType key')
}
if (typeof DataType !== 'string') {
@maowug
maowug / diff on groupBy and map in rxjs.js
Created February 14, 2016 09:22
diff on groupBy and map in rxjs
//
//groupBy: <K, R>(keySelector: (value: T) => K, elementSelector?: (value: T) => R, durationSelector?: (group: GroupedObservable<K, R>) => Observable<any>) => Observable<GroupedObservable<K, R>>;
//
//map: <R>(project: (x: T, ix?: number) => R, thisArg?: any) => Observable<R>;
var codes = [
{ keyCode: 38}, // up
{ keyCode: 38}, // up
{ keyCode: 40}, // down
@maowug
maowug / garoon.js
Last active February 14, 2016 05:08
garoon api
const Promise = require('bluebird')
const request = require('request')
const cheerio = require('cheerio')
const moment = require('moment')
const _ = require('lodash')
class GaroonClient {
constructor () {
this.jar = request.jar()
this.url = {
@maowug
maowug / StringDecoder.js
Created February 13, 2016 08:11
StringDecoder clip
var StringDecoder = exports.StringDecoder = function(encoding) {
this.encoding = (encoding || 'utf8').toLowerCase().replace(/[-_]/, '');
assertEncoding(encoding);
switch (this.encoding) {
case 'utf8':