Skip to content

Instantly share code, notes, and snippets.

View jirick1's full-sized avatar
🎯
Focusing

James jirick1

🎯
Focusing
  • NYC
View GitHub Profile
@jirick1
jirick1 / multipartformtojson.scala
Created May 4, 2020 18:17
Scala MultipartFormData to Json String
def multipartToJsonString(req: Option[MultipartFormData[Files.TemporaryFile]]): String = {
val jsFields = req.head.dataParts.flatMap {
case (key, values) => values.map { value =>
if (key == "product_id" || !isAllDigits(value)) s""" "$key": "$value" """ // treat product_id as a string
else s""" "$key": ${value.toInt} """
}
}
s"{${jsFields.mkString(",")}}"
}
@jirick1
jirick1 / DynamicSlickSort.scala
Created March 21, 2020 20:04 — forked from Daenyth/DynamicSlickSort.scala
Slick support for dynamic sort with pagination
import slick.lifted.Rep
import slick.ast.Ordering.Direction
import slick.ast.Ordering
import slick.lifted.Query
import slick.lifted.ColumnOrdered
import slick.lifted.Ordered
import scala.util.control.NoStackTrace
case class PageRequest(offset: Int,
# taken from http://www.piware.de/2011/01/creating-an-https-server-in-python/
# generate server.xml with the following command:
# openssl req -new -x509 -keyout server.pem -out server.pem -days 365 -nodes
# run as follows:
# python simple-https-server.py
# then in your browser, visit:
# https://localhost:4443
import BaseHTTPServer, SimpleHTTPServer
import ssl
@jirick1
jirick1 / gist:bbe210f4aa98ee568d3ddb64c8bde44e
Created August 27, 2019 10:05 — forked from cvogt/gist:9193220
Slick: Dynamic query conditions using the **MaybeFilter** (Updated to support nullable columns)
import scala.slick.lifted.CanBeQueryCondition
// optionally filter on a column with a supplied predicate
case class MaybeFilter[X, Y](val query: scala.slick.lifted.Query[X, Y]) {
def filter[T,R:CanBeQueryCondition](data: Option[T])(f: T => X => R) = {
data.map(v => MaybeFilter(query.filter(f(v)))).getOrElse(this)
}
}
// example use case
import java.sql.Date
@jirick1
jirick1 / connectHTMLelements_SVG.png
Created April 7, 2019 19:29 — forked from pouyakary/connectHTMLelements_SVG.png
Connect two elements / draw a path between two elements with SVG path (using jQuery)
connectHTMLelements_SVG.png
/*
Generates a populated Job Card PDF using the data in the supplied array and returns an application file path to the newly generated PDF.
Requires the inclusion of the util function: 'generateJobCardFDF($inputData)'
*/
function generatePopulatedJobCardPDF($jobCardData){
//Format the form data
$formData['Job_Number']=$jobCardData[''];
$formData['Customer']=$jobCardData[''];
$formData['Description']=$jobCardData[''];
<html>
<head>
<style type="text/css">
.clear{
clear:both;
}

Sublime Text 2 – Useful Shortcuts (Mac OS X)

General

⌘T go to file
⌘⌃P go to project
⌘R go to methods
⌃G go to line
⌘KB toggle side bar
⌘⇧P command prompt
#!/bin/sh
# All the things I can install from the command line when I set up a new Mac
# This can be executed by copying and pasting the following at a shell prompt
# curl https://raw.github.com/gist/2993226/initial_setup.sh | sh
# Install Homebrew
ruby -e "$(curl -fsSkL raw.github.com/mxcl/homebrew/go)"
# Homebrew packages
brew install python25 python26 python python32 python3 pypy