Skip to content

Instantly share code, notes, and snippets.

import scala.xml._
import java.net.{URLConnection, URL}
class RSSRead {
def getFeed(feedUrl: String) = {
val url = new URL(feedUrl)
val connect = url.openConnection
val feed = XML.load(connect.getInputStream)
feed \\ "channel" \\ "item"
(* Basic OCaml Tokyo Tyrant Client.
* Currently, only supports get and put, but may eventually add all
* the exciting other features.
*
* -Cooper Francis.
*)
#use "topfind";;
#camlp4o;;
#require "lwt";;
#require "unix";;
(defn listify [orig-list]
"Turns (1 2 3 ...) into (1 (2 (3 (...)))) using continuation passing style."
(loop [lst orig-list cont identity]
(if (= () lst)
(cont ())
(recur (rest lst)
(fn [insert]
(cont (cons (first lst)
(list insert))))))))
java.lang.ArrayIndexOutOfBoundsException: 42
at scala.tools.nsc.ast.TreeGen.scalaFunctionConstr(TreeGen.scala:36)
at scala.tools.nsc.typechecker.Unapplies$class.createFun$1(Unapplies.scala:138)
at scala.tools.nsc.typechecker.Unapplies$class.parents$1(Unapplies.scala:139)
at scala.tools.nsc.typechecker.Unapplies$class.caseModuleDef(Unapplies.scala:141)
at scala.tools.nsc.Global$analyzer$.caseModuleDef(Global.scala:291)
at scala.tools.nsc.typechecker.Namers$Namer$$anonfun$5.apply(Namers.scala:354)
at scala.tools.nsc.typechecker.Namers$Namer$$anonfun$5.apply(Namers.scala:354)
at scala.tools.nsc.typechecker.Namers$Namer.ensureCompanionObject(Namers.scala:296)
at scala.tools.nsc.typechecker.Namers$Namer.enterSym(Namers.scala:354)
require("gtools")
require("hash")
# Thunks an expression. Basic lazy evaluation.
thunk <- defmacro(x, expr=function() x)
# But it turns out this is unnecessary! R lazily evaluates its arguments!
thunk2 <- function(x) { function() { x } }
# Further:
delayedAssign("x", 1/0)
# actually is better than what I'd implemented so far: creates a promise for
java.lang.NullPointerException
at scala.Array$$anon$2.apply(Array.scala:46)
at scala.Array$$anon$2.apply(Array.scala:45)
at scala.collection.TraversableLike$class.flatMap(TraversableLike.scala:226)
at scala.collection.mutable.ArrayOps.flatMap(ArrayOps.scala:34)
> lst
[,1] [,2] [,3]
[1,] "3" "2" "1"
> table(lst, lst)
Error in sort.list(y) :
'x' must be atomic for 'sort.list'
Have you called 'sort' on a list?
> traceback()
4: stop("'x' must be atomic for 'sort.list'\nHave you called 'sort' on a list?")
3: sort.list(y)
// From the repl:
scala> val features: Seq[Array[FeatureNode]] = values._2
features: Seq[Array[liblinear.FeatureNode]] = List(Array(FeatureNode(idx=1, value=1.0)), Array(FeatureNode(idx=2, value=1.0)))
scala> features.toArray
res5: Array[Array[liblinear.FeatureNode]] = Array(Array(FeatureNode(idx=1, value=1.0)), Array(FeatureNode(idx=2, value=1.0)))
// But when this is otherwise executed:
[info] null (TraversableOnce.scala:388)
[info] scala.collection.TraversableOnce$class.toArray(TraversableOnce.scala:388)
[info] scala.collection.immutable.List.toArray(List.scala:45)
Dim StripeURL, APIKey
StripeURL = "https://api.stripe.com/v1/charges"
APIKey = <YOUR SECRET KEY>
Function makeStripeAPICall(requestBody)
Dim objXmlHttpMain
Set objXmlHttpMain = CreateObject("Msxml2.ServerXMLHTTP")
On Error Resume Next
objXmlHttpMain.open "POST", StripeURL, False
@agentcoops
agentcoops / gist:ec24f824fcdd36bd4963
Created August 23, 2015 16:13
Pharo Stripe Request
| znc response |
ZnNetworkingUtils defaultSocketStreamTimeout: 60.
(znc := ZnClient new) logToTranscript.
response := znc
url: 'https://api.stripe.com/v1/charges';
headerAt: 'Authorization'
add: ('BEARER {1}' format: { <YOUR KEY> });
formAt: 'amount' put: '1000';