Skip to content

Instantly share code, notes, and snippets.

View aldonline's full-sized avatar

Aldo Bucchi aldonline

  • Decoupled Inc
  • San Francisco - Bay Area
View GitHub Profile
@aldonline
aldonline / typed_state_machines.test.ts
Last active April 14, 2021 21:28
Typed State Machine
import { SM, Clazz } from "./typed_state_machines"
interface ITalker {
say_hello(name: string): string
repeat(message: string)
}
// the root state is implemented by a class that extends SM (State Machine)
class Talker extends SM implements ITalker {
say_hello(name: string): string {
import * as fs from "fs-extra"
import { ensureDirSync } from "fs-extra"
import { LazyGetter as lazy } from "lazy-get-decorator"
import { Memoize as memo } from "lodash-decorators"
import { dirname, join } from "path"
import vscode from "vscode"
import { degit_with_retries } from "../../../degit/degit_with_retries"
import { GitURL } from "../../../git/GitURL"
import { TargetDirSpecification } from "../../util/TargetDirSpecification"
import { TargetDirSpecification_resolve_vsc } from "../../util/TargetDirSpecification_resolve_vsc"
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
<#me> foaf:name "Aldo Bucchi" ;
foaf:member <http://dbpedia.org/resource/MuleSoft> ;
foaf:knows <https://gist.githubusercontent.com/blakeembrey/d292d0d182947932114a/raw/me.ttl#me>
.
##1 How-to
Everybody knows what **looping** over a collection is. But do you know what **reducing** a collection means?
No? Are you sure?
It sounds scary. But it is in fact pretty simple. You do it all the time.
Here. Let me show you an example:
<!--code lang=javascript linenums=true-->
@aldonline
aldonline / affirmation
Created December 24, 2014 20:57
MuleSoft Contributor Agreement Acceptance by Aldo Bucchi
I, Aldo Bucchi, have read and do accept the MuleSoft Contributor Agreement
at http://www.mulesoft.org/legal/contributor-agreement.html
Accepted on Wed Dec 24 2014 17:57:06 GMT-0300 (CLST)
radioactive.react(function(){
var userId = getTextInputValue();
var userName = getNameFromServer( userId );
console.log( userName );
})
@aldonline
aldonline / gist:865d2331fb02cdfdd31c
Created October 8, 2014 08:11
scala-js version of radioactive
package radioactivejs
import org.scalajs.dom
import _root_.util.StackVal
import org.scalajs.dom.{Event, HTMLElement}
import scala.collection.mutable
import scala.util.Try
import scala.scalajs.js
@aldonline
aldonline / gist:6959105
Created October 13, 2013 07:21
SQL string to Scala Stream[ResultSet] and common Loan pattern usages when dealing with SQL connections
object x {
// stream a sql query
def sql( str:String ):Stream[ResultSet] = withStatement { s =>
val rs = s executeQuery str
new Iterator[ResultSet] { def hasNext = rs.next ; def next = rs }.toStream
}
// loan a sql statement
@aldonline
aldonline / gist:6959067
Created October 13, 2013 07:16
polymorphic map() over Google Apps Script iterators and Arrays.
function _map( coll, f ){
var res = []
var isIterator = ( typeof coll.next == "function" )
var isArray = ( coll instanceof Array )
var hasFunc = ( typeof f == "function" )
var append = function(e){ res.push( hasFunc ? f(e) : e ) }
if( isIterator ){
while( coll.hasNext() ){ append( coll.next() ) }
} else if ( isArray ) {
coll.forEach(append)
@aldonline
aldonline / gist:6959006
Created October 13, 2013 07:06
Given a Java class name get the path of its containing jar
Class.forName(c).getProtectionDomain.getCodeSource.getLocation()