Skip to content

Instantly share code, notes, and snippets.

View Centaur's full-sized avatar

oldpig Centaur

  • singerdream.com
  • Shanghai
View GitHub Profile
@Centaur
Centaur / gist:4070883
Created November 14, 2012 07:52 — forked from non/gist:4064198
Add map + flatMap to Function1-3 with no overhead
object RichF {
implicit class RichF1[A, Z](val f: A => Z) extends AnyVal {
def map[Y](g: Z => Y): A => Y =
(a: A) => g(f(a))
def flatMap[Y](g: Z => A => Y): A => Y =
(a: A) => g(f(a))(a)
}
implicit class RichF2[A, B, Z](val f: (A, B) => Z) extends AnyVal {
def map[Y](g: Z => Y): (A, B) => Y =
private val _jqueryCssSelectRegex = """(^\S)+""".r
private val _matchChar = Set('*', '[', '^', '-')
def sel(exp: String, content: NodeSeq): CssSel = {
val selects = _jqueryCssSelectRegex.findAllMatchIn(exp).map(_.matched).toList
val (init, last) =
if (_matchChar.contains(selects.last.head))
selects.dropRight(2) -> selects.takeRight(2).mkString(" ")
else
import scala.xml.NodeSeq
import net.liftweb.http.js._
import net.liftweb.http.js.jquery._
def $(exp: String): jQuery = $(JE.Str(exp))
def $(exp: JsExp): jQuery = jQuery(exp)
case class jQuery(exp: JsExp) {

Each of these commands will run an ad hoc http static server in your current (or specified) directory, available at http://localhost:8000. Use this power wisely.

Discussion on reddit.

Python 2.x

$ python -m SimpleHTTPServer 8000
// You won't be able to compile this with:
// scala -language:dynamics NoDynamics.scala
// These two ambiguous implicits disable the `dynamics` feature.
implicit def ambDynamics1: language.dynamics.type = ???
implicit def ambDynamics2: language.dynamics.type = ???
object Woo extends Dynamic {
def selectDynamic(name: String) = s"$name a mess of a language"

I'm having trouble understanding the benefit of require.js. Can you help me out? I imagine other developers have a similar interest.

From Require.js - Why AMD:

The AMD format comes from wanting a module format that was better than today's "write a bunch of script tags with implicit dependencies that you have to manually order"

I don't quite understand why this methodology is so bad. The difficult part is that you have to manually order dependencies. But the benefit is that you don't have an additional layer of abstraction.


tmux shortcuts & cheatsheet

start new:

tmux

start new with session name:

tmux new -s myname
realm=Sonatype Nexus Repository Manager
host=nexus.company.com
user=admin
password=admin123
/*
* Copyright (C) 2013 Square, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@Centaur
Centaur / answer.md
Last active August 29, 2015 14:20 — forked from non/answer.md

What is the appeal of dynamically-typed languages?

Kris Nuttycombe asks:

I genuinely wish I understood the appeal of unityped languages better. Can someone who really knows both well-typed and unityped explain?

I think the terms well-typed and unityped are a bit of question-begging here (you might as well say good-typed versus bad-typed), so instead I will say statically-typed and dynamically-typed.

I'm going to approach this article using Scala to stand-in for static typing and Python for dynamic typing. I feel like I am credibly proficient both languages: I don't currently write a lot of Python, but I still have affection for the language, and have probably written hundreds of thousands of lines of Python code over the years.