This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // scala string interpolation examples | |
| // https://docs.scala-lang.org/overviews/core/string-interpolation.html | |
| import scala.language.implicitConversions | |
| object TestStringInterpolation extends App { | |
| // s string interpolation | |
| val name = "James" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| on alfred_script() | |
| tell application "IINA" | |
| activate | |
| tell application "System Events" to keystroke "space" | |
| end tell | |
| end alfred_script |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // from https://www.safaribooksonline.com/library/view/scala-cookbook/9781449340292/ch01s11.html | |
| import scala.language.implicitConversions | |
| // String to user-defined case class | |
| implicit class Name(name: String) { | |
| def toName(): Name = new Name(name) | |
| override def toString() = s"Name($name)" | |
| } | |
| // Name("Joe").toName |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include "rapidjson/document.h" | |
| #include "rapidjson/stringbuffer.h" | |
| #include "rapidjson/writer.h" | |
| using namespace rapidjson; | |
| int main(int argc, char* argv[]) { | |
| const char* json = "{\n" | |
| " \"hello\": \"world 中文测试\",\n" | |
| " \"t\": true ,\n" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| for proc in $(find /proc -maxdepth 1 -regex '/proc/[0-9]+'); do | |
| printf "%2d %5d %s\n" \ | |
| "$(cat $proc/oom_score)" \ | |
| "$(basename $proc)" \ | |
| "$(cat $proc/cmdline | tr '\0' ' ' | head -c 100)" | |
| done 2>/dev/null | sort -nr | head -n 20 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Y combinator:http://yaodanzhang.com/blog/2015/06/11/functional-programming-fundamental-y-combinator/ | |
| // lambda 演算:http://liujiacai.net/blog/2014/10/12/lambda-calculus-introduction/ | |
| // Jim Weirich: Adventures in Functional Programming:https://vimeo.com/45140590 | |
| // original recursive function | |
| var factorial = function (n) { | |
| return n == 1 ? 1 : n * factorial(n - 1); | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python | |
| # encoding: utf-8 | |
| """ | |
| @author: wujiabin | |
| @date: 2016.5.4 | |
| @brief: based on http://flask.pocoo.org/snippets/134/ | |
| """ | |
| import os |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def _resolve(name): | |
| """Resolve a dotted name to a global object.""" | |
| name = name.split('.') | |
| used = name.pop(0) | |
| found = __import__(used) | |
| for n in name: | |
| used = used + '.' + n | |
| try: | |
| found = getattr(found, n) | |
| except AttributeError: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python | |
| def trailing_zeroes(num): | |
| """Counts the number of trailing 0 bits in num.""" | |
| if num == 0: | |
| return 32 # Assumes 32 bit integer inputs! | |
| p = 0 | |
| while (num >> p) & 1 == 0: | |
| p += 1 | |
| return p |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python2.7 | |
| # encoding: utf-8 | |
| """ the same with scala code belows | |
| abstract class Nat { | |
| def isZero: Boolean | |
| def predecessor: Nat | |
| def successor: Nat = new Succ(this) | |
| def +(that: Nat): Nat | |
| def -(that: Nat): Nat |