Skip to content

Instantly share code, notes, and snippets.

View stanch's full-sized avatar

Nick stanch

  • Product Manager at @snowplow
  • Lisbon, Portugal
View GitHub Profile
/* "a123b45c" → ["a", 123, "b", 45, "c"] */
function nat(x) {
// digit-parts
var d = x.split(/[^0-9]+/); // ["", "123", "45, ""]
// alpha-parts
var a = x.split(/[0-9]+/); // ["a", "b", "c"]
// helpers
function nonEmpty(x) { return x != "" }
function toInt(x) { return x - 0 }
// the one that does not start with a "" goes first
import org.scalajs.dom
import scalatags.HtmlTag
import scalatags.all._
import scalatags._
@JSExport
object ScalaJSExample {
@JSExport
def main(args: Array[String]) = {
val rx1 = Var(1)
val rx2 = Var(2)
val rx3 = Rx { rx1() + rx2() }
// ...
val style = TextSize.large + padding(all = 16 dp)
def rxText(rx: Rx[Int]) = rx.map(_.toString).map(text)
// -- in the activity:
var navSlot = slot[ListView]
var drawerSlot = slot[DrawerLayout]
// -- in onCreate:
// ListView tweaks
def checkItem(pos: Int) = Tweak[ListView](_.setItemChecked(pos, true))
val singleNoDivider = Tweak[ListView] { lv ⇒
import android.content.Context
import android.util.Log
import android.view.{View, ViewGroup}
import macroid.AppContext
import macroid.MediaQueries._
object Spec {
def apply(size: Int, mode: Int) =
View.MeasureSpec.makeMeasureSpec(size, mode)
@active
class A {
// all non-@active locals
// will be made private
var y = 0
def bar(x: Int) = x + 5
@active // should return Unit
def foo(x: Int) = {
y = bar(x)
// some other android imports here
...
import android.support.v4.app.{ Fragment, FragmentManager, FragmentPagerAdapter }
import android.support.v4.view.ViewPager
import com.viewpagerindicator.TitlePageIndicator
import macroid._
import macroid.FullDsl._
import macroid.contrib._
import macroid.contrib.Layouts._
@stanch
stanch / classdiag.py
Last active January 14, 2016 17:52
A quick-n-dirty way to convert Scala case class definitions into http://yuml.me/diagram/plain/class/draw class diagrams
#!/usr/bin/env python3
import os
import re
import sys
import fnmatch
entities = {}
relations = {}
@stanch
stanch / config.fish
Created January 18, 2016 23:20
My entire fish shell configuration
# In ~/.config/fish/config.fish
set fish_greeting
set __fish_git_prompt_showdirtystate 'yes'
@stanch
stanch / ScalaJSExample.scala
Last active January 20, 2016 01:50
Scala.js template for scala-js-fiddle
import scalatags.JsDom.all._
object ScalaJSExample extends js.JSApp {
def main() = {
}
}