Skip to content

Instantly share code, notes, and snippets.

View heathermiller's full-sized avatar

Heather Miller heathermiller

View GitHub Profile
/** @constructor */
ScalaJS.c.example_Person = (function() {
ScalaJS.c.java_lang_Object.call(this);
this.name$1 = null;
this.age$1 = 0
});
ScalaJS.c.example_Person.prototype = new ScalaJS.inheritable.java_lang_Object();
ScalaJS.c.example_Person.prototype.constructor = ScalaJS.c.example_Person;
ScalaJS.c.example_Person.prototype.name__T = (function() {
return this.name$1
(function(){'use strict';function e(a){return function(){return this[a]}}function f(a){return function(){return a}}var k,aa="object"===typeof global&&global&&global.Object===Object?global:this,ba="object"===typeof __ScalaJSExportsNamespace&&__ScalaJSExportsNamespace?__ScalaJSExportsNamespace:"object"===typeof global&&global&&global.Object===Object?global:this;function ca(a){return function(b,c){return!(!b||!b.a||b.a.Ra!==c||b.a.Qa!==a)}}function da(a){var b,c;for(c in a)b=c;return b}function n(a){return!(!a||!a.a)}
function p(a,b){throw(new ea).x(a+" is not an instance of "+b);}
function fa(a,b){var c;if(n(a))if(ga(),a===b)c=!0;else if(q(a))if(c=ha(a),q(b)){var d=ha(b),h=ia(c),g=ia(d),h=g>h?g:h;switch(h){default:c=h===s().K?c.y()===d.y():h===s().X?c.B().j(d.B()):h===s().W?c.P()===d.P():h===s().V?c.N()===d.N():d&&d.a&&d.a.g.cc&&!(c&&c.a&&c.a.g.cc)?t(d,c):null===c?null===d:t(c,d)}}else u(b)?(d=ja(b),c=ka(c,d)):c=null===c?null===b:t(c,b);else u(a)?(c=ja(a),u(b)?(d=ja(b),c=c.m===d.m):q(b)?(d=ha(b),c=ka(d,c)):c=nu
val codeToChars: Map[Char, String] =
Map(
'2' -> "ABC", '3' -> "DEF", '4' -> "GHI", '5' -> "JKL",
'6' -> "MNO", '7' -> "PQRS", '8' -> "TUV", '9' -> "WXYZ"
)
/**
* Inverse of codeToChars,
* e.g. 'A' -> '2', 'B' -> '2'.
*/
@heathermiller
heathermiller / reflect-extract-ctor-args.scala
Last active June 13, 2022 21:45
Getting constructor arguments out of a case class, printing the names of the args and their runtime values
import scala.reflect.runtime.universe._
class AbstractParams[T: TypeTag] {
def tag: TypeTag[T] = typeTag[T]
override def toString: String = {
// Find all case class fields in concrete class instance and print them as "[field name] [field value]"
val tag = this.tag
val tpe = tag.tpe
val allAccessors = tpe.declarations.collect { case meth: MethodSymbol if meth.isCaseAccessor => meth }
@heathermiller
heathermiller / tagged.scala
Created November 12, 2014 21:33
TypeInfo pickling
package tagged
import scala.pickling._
import internal._
import json._
// final case class TypeInfo(erasureClass: String, typeArguments: Seq[TypeInfo] = Seq.empty)
// final case class AttributeKey(name: String, manifest: TypeInfo)
@heathermiller
heathermiller / so.xml
Created April 7, 2015 19:34
Excerpt of StackOverflow dump
<?xml version="1.0" encoding="UTF-8" ?>
<row Id="4" PostTypeId="1" AcceptedAnswerId="7" CreationDate="2008-07-31T21:42:52.667" Score="322" ViewCount="21888" Body="&lt;p&gt;I want to use a track-bar to change a form's opacity.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is my code:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;decimal trans = trackBar1.Value / 5000;&#xA;this.Opacity = trans;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;When I try to build it, I get this error:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA; &lt;p&gt;Cannot implicitly convert type 'decimal' to 'double'.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;I tried making &lt;code&gt;trans&lt;/code&gt; a &lt;code&gt;double&lt;/code&gt;, but then the control doesn't work. This code has worked fine for me in VB.NET in the past. &lt;/p&gt;&#xA;" OwnerUserId="8" LastEditorUserId="451518" LastEditorDisplayName="Rich B" LastEditDate="2014-07-28T10:02:50.557" LastActivityDate="2014-12-20T17:18:47.807" Title="When setting a form's opacity should I use a
@heathermiller
heathermiller / scala-cheatsheet.md
Last active February 11, 2024 15:56
Scala Cheatsheet

This cheat sheet originated from the forum, credits to Laurent Poulain. We copied it and changed or added a few things.

Evaluation Rules

  • Call by value: evaluates the function arguments before calling the function
  • Call by name: evaluates the function first, and then evaluates the arguments if need be
    def example = 2      // evaluated when called
    val example = 2      // evaluated immediately
[info] Loading project definition from /grader/project
[info] Set current project to grader (in build file:/grader/)
[info] Updating {file:/grader/}parprog1...
[info] Resolving org.scala-lang#scala-library;2.11.7 ...

[info] Resolving ch.epfl.lamp#scala-grading-runtime_2.11;0.3 ...

[info] Resolving org.scala-lang.modules#scala-pickling_2.11;0.10.0 ...

[info] Resolving org.scala-lang#scala-compiler;2.11.4 ...
⌘ ~/Dropbox/git-shared/moocs (master) sbt
[info] Loading project definition from /Users/hmiller/Dropbox/git-shared/moocs/project
[info] Set current project to root (in build file:/Users/hmiller/Dropbox/git-shared/moocs/)
>
>
> parprog1/gradeLocal scalashop
[error] Expected configuration
[error] Expected ':' (if selecting a configuration)
[error] Expected key
[error] Expected '::'
@heathermiller
heathermiller / gist:61882184ffdd6433cc23
Created February 22, 2016 18:15
createHandout issue
⌘ ~/Dropbox/git-shared/moocs/courses/progfun1/target/patmat (master) sbt
[info] Loading project definition from /Users/hmiller/Dropbox/git-shared/moocs/courses/progfun1/target/patmat/project
[info] Set current project to progfun1-patmat (in build file:/Users/hmiller/Dropbox/git-shared/moocs/courses/progfun1/target/patmat/)
> compile
[info] Compiling 2 Scala sources to /Users/hmiller/Dropbox/git-shared/moocs/courses/progfun1/target/patmat/target/scala-2.11/classes...
[error] /Users/hmiller/Dropbox/git-shared/moocs/courses/progfun1/target/patmat/src/main/scala/patmat/Huffman.scala:117: not found: type ???
[error] def until(xxx: ???, yyy: ???)(zzz: ???): ??? = ???
[error] ^
[error] /Users/hmiller/Dropbox/git-shared/moocs/courses/progfun1/target/patmat/src/main/scala/patmat/Huffman.scala:117: not found: type ???
[error] def until(xxx: ???, yyy: ???)(zzz: ???): ??? = ???