Skip to content

Instantly share code, notes, and snippets.

@mguillermin
mguillermin / generated_jsRoutes.js
Last active May 24, 2016
Submitting Ajax POST with PlayFramework 2.x and the Javascript Router
View generated_jsRoutes.js
...
_nS('controllers.admin.Products'); _root.controllers.admin.Products.search =
function() {
return _wA({method:"POST", url:"/" + "admin/product/search"})
}
...
View repeatWithIndex.scala.html
@(field:Field, min:Int=1)(f: (Field, Int) => Html)
@{
(0 until math.max(if (field.indexes.isEmpty) 0 else field.indexes.max + 1, min)).map(i => f(field("[" + i + "]"),i))
}
View Find Datomic ident names
Datomic.q(Query(
s"""[:find ?name
:in $$
:where [_ :db/ident ?ident]
[(namespace ?ident) ?ns]
[(name ?ident) ?name]
[(= ?ns "namespace_name")]
]"""
), database).foreach {
case name: String => println(name)
@tanitanin
tanitanin / optionBinder.scala
Last active Jul 27, 2018
QueryStringBindable and Formatter for Option[T] ( @ Play Framework 2.x )
View optionBinder.scala
import play.api.data._
import play.api.data.format._
import play.api.data.format.Formats._
/**
* Option[T]をクエリとして解決するためのバインダ(必須でないパラメータなどに利用することを想定)
* 通常のFormと同様にbindFromRequestして使う
* クエリに該当するキーが含まれていない場合にはFormの値がNoneになる
*
* こんなかんじ (もっときれいに書きたいけど):
@nickdandakis
nickdandakis / package.json
Last active Apr 11, 2019
Next.js + AWS Elastic Beanstalk + AWS EC2 Container Service + Docker package.json
View package.json
{
"name": "this-web-scale",
"version": "0.0.1",
"scripts": {
"dev": "node server.js",
"build": "NODE_ENV=production next build",
"start": "NODE_ENV=production node server.js",
"dockerize": "npm run build:docker && npm run tag:docker && npm run push:docker && npm run tag-latest:docker && npm run push-latest:docker",
"deploy": "eb use this-web-scale-production && eb deploy --label v$npm_package_version --verbose",
"build:docker": "docker build -t $npm_package_config_docker_image:$npm_package_version -t $npm_package_config_docker_image:latest .",
View turbolinks_prefetch.coffee
@ryanttb
ryanttb / install_node_lsw.sh
Last active Dec 4, 2019
Install node on Linux Subsystem for Windows
View install_node_lsw.sh
#!/bin/sh
# this script requires root
# be sure to run the following before running this:
# $ sudo su
# since there's an issue piping the curl response to bash
# just download the install script
curl -sL https://deb.nodesource.com/setup_6.x > install_node.sh
@nyango
nyango / WildcardAllowedCORSFilterFactory.scala
Last active Dec 24, 2019
Play CORS Filter with wildcard origin matching
View WildcardAllowedCORSFilterFactory.scala
import javax.inject.{Inject, Singleton}
import akka.stream.Materializer
import play.api.Configuration
import play.filters.cors.CORSConfig.Origins.Matching
import play.filters.cors.{CORSConfig, CORSFilter}
import scala.concurrent.ExecutionContext
import scala.util.matching.Regex
@magicspon
magicspon / server.js
Created Nov 7, 2018
using https with next
View server.js
const https = require('https')
const { parse } = require('url')
const next = require('next')
const fs = require('fs')
const dev = process.env.NODE_ENV !== 'production'
const app = next({ dev })
const handle = app.getRequestHandler()
const options = {
View ScalaProtobufSerializer.scala
package ws.eiennohito.utils.serialization
import java.lang.reflect.Modifier
import java.util.concurrent.ConcurrentHashMap
import akka.serialization.Serializer
import com.google.protobuf.CodedOutputStream
import com.trueaccord.scalapb.{GeneratedMessage, GeneratedMessageCompanion}
import com.typesafe.scalalogging.StrictLogging