Skip to content

Instantly share code, notes, and snippets.

@trepidacious
trepidacious / gist:4002316
Created November 2, 2012 16:06
User form
object InsertUserView {
def newUser(email: String) = {
val u = new User()
u.email() = email
Data.mb.keep(u)
u
}
def findOrNew(email: String) = {
val u = Data.mb.findOne[User](MongoDBObject("email" -> email))
u.getOrElse(newUser(email))
@trepidacious
trepidacious / gist:4002351
Created November 2, 2012 16:09
User form
class InsertUserView(t: User) extends InsertCometView[User](t){
def makeView(t: User) = AjaxListOfViews(ListVal(allViews))
private val allViews = List[AjaxView](
AjaxTextView( "Email", Path{t.email}),
AjaxTextView( "First Name", Path{t.firstName}),
AjaxTextView( "Last Name", Path{t.lastName}),
AjaxPassView( Path(t.passHash)),
AjaxStringView( "Validated", Cal{t.validated()})
@trepidacious
trepidacious / gist:5652812
Last active December 17, 2015 18:19
Problem with => Unit
package boxes.util
trait Op {
def apply()
}
class OpDefault(action: => Unit) extends Op {
def apply() {
action
}
@trepidacious
trepidacious / gist:5693116
Created June 2, 2013 09:18
Plotting a square wave
def plotSignal(c: Channel) = {
def alternating(s: Boolean): Stream[Boolean] = s #:: alternating(!s)
def y(s: Boolean) = if (s) 1 else 0
c.signal().changeTimes.zip(alternating(c.signal().initialState)).flatMap{case(time, state) => List(Vec2(time, y(state)), Vec2(time, y(!state)))}
}
@trepidacious
trepidacious / gist:5748580
Created June 10, 2013 13:09
Generate local mac address
void mcu_generate_local_mac(uint8_t *mac) {
uint32_t i = 0;
uint32_t m_w = 0;
uint32_t m_z = 0;
for (i = 0; i < 4; i++) {
m_w = (m_w << 8) + mcu_unique_device_id_byte(i*3);
m_z = (m_z << 8) + mcu_unique_device_id_byte(i*3 + 2);
}
m_w += mcu_unique_device_id_byte(1) * 5 + mcu_unique_device_id_byte(7) * 7;
public class ListBuilder {
private final StringBuilder b = new StringBuilder();
public ListBuilder li(String s) {
if (s!=null && !s.trim().isEmpty()) {
b.append("<li>"); b.append(s); b.append(</li>);
}
return this;
}
public String toString() {
@trepidacious
trepidacious / fsmc.c
Created July 26, 2013 10:59
FSMC config for PSRAM
#include "ch.h"
#include "hal.h"
#include "stmdrivers/stm32f4xx_rcc.h"
#include "stmdrivers/stm32f4xx_fsmc.h"
void fsmc_early_init(void) {
FSMC_NORSRAMInitTypeDef FSMC_NORSRAMInitStructure;
FSMC_NORSRAMTimingInitTypeDef p;
rccEnableAHB3(RCC_AHB3ENR_FSMCEN, FALSE);
@trepidacious
trepidacious / JSON
Created February 18, 2015 15:16
Conversion via tokens to XML and JSON
{
"_type_": "Person",
"_id_": 0,
"name": "name",
"friend": {
"_type_": "Option",
"Some": {
"_type_": "Person",
"_id_": 1,
"name": "q",
@trepidacious
trepidacious / readme.md
Created February 20, 2015 20:21
Android + Scala + SBT + Idea
  1. Install IDEA 14 Community edition
  2. In Idea:
    1. Install Scala plugin (Preferences -> Plugins, type Scala at top, install)
    2. Install Android Support plugin
  3. Check out an android project using android-sdk-plugin, e.g. https://github.com/macroid/macroid-starter
  4. Import into IDEA using SBT import. File->Import Project, navigate to root of project, import as SBT.
  5. For SDK, choose the android option.
  6. If necessary, create Scala library when prompted.
  7. Delete "Make" from any run configuration(s). Run-> Edit Configurations... then in the activity, scroll to bottom and delete Make from the "Before launch" list.
  8. Build and run the project from SBT, but you can edit it in IDEA.
195.3 ms13.41 % 195.3 ms13.41 % Chart.bundle.js:7736helpers.clone
194.0 ms13.32 % 194.0 ms13.32 % Chart.bundle.js:6333(anonymous function)
194.0 ms13.32 % 194.0 ms13.32 % Chart.bundle.js:6331Chart.controllers.line.Chart.DatasetController.extend.updateBezierControlPoints
192.8 ms13.24 % 192.8 ms13.24 % Chart.bundle.js:6148Chart.controllers.line.Chart.DatasetController.extend.addElementAndReset
192.8 ms13.24 % 192.8 ms13.24 % Chart.bundle.js:7577buildOrUpdateElements
192.8 ms13.24 % 192.8 ms13.24 % Chart.bundle.js:7218(anonymous function)
192.8 ms13.24 % 192.8 ms13.24 % Chart.bundle.js:7714helpers.each
192.8 ms13.24 % 192.8 ms13.24 % Chart.bundle.js:7203update
192.8 ms13.24 % 192.8 ms13.24 % :5000/elements/boxes-scatter/boxes-scatter.html:101(anonymous function)
192.8 ms13.24 % 192.8 ms13.24 % :5000/bower_components/polymer/polymer.html:1291(anonymous function)