Skip to content

Instantly share code, notes, and snippets.

View phillro's full-sized avatar

Phillip Rosen phillro

View GitHub Profile
@phillro
phillro / gist:1193227
Created September 4, 2011 17:59
Elasticsearch autocomplete example with cross origin resource sharing
<html>
<head>
<link rel="stylesheet" href="/examples/stylesheets/ui-lightness/jquery-ui-1.8.16.custom.css" type="css">
<script type="text/javascript" src="/examples/javascripts/jquery.min.js"></script>
<script type="text/javascript" src="/examples/javascripts/jquery.base64.min.js"></script>
<script type="text/javascript" src="/examples/javascripts/jquery-ui-1.8.16.custom.min.js"></script>
<script type="text/javascript" src="/examples/javascripts/jquery.tmpl.min.js"></script>
</head>
<body>
function scalingBidModifier {
maxScaleFactor = .4
rootScaleValue = $25
scalingFloor = $5
If(bid>scalingFloor){
var modifier = if(bid>=rootScaleValue){
1-maxScaleFactor
} else {
-----BEGIN PGP PUBLIC KEY BLOCK-----
Comment: GPGTools - https://gpgtools.org
mQENBFnmbRQBCADDvPXs4PUsDh0/5BajVFnMiLdxzrNOMAaCPYorhJ++Le6m0She
oFCRW6Z/2AoedA9t+zlbgD9LWR3FUNBibcmU1CwbCtPKwJB/9hZNScULjdQicJ6P
YK4JQuAuU4RkTa7uaw6KpeKw8aXGhb/JxOTrUbFdZ/rMPZVkZJ62A4AQph2cDX8i
9WzmCmOYHDmQvJo6dkWHLDDGXFsWuwPWB/uKsHKXh68sK+QjmObKJ10T1K1/xkVE
GfeZ3usB/4WMgqS87yHF5abZAtpo38KK6XAyUX4Q5aqKm5ZvX3hP63ezFW97+fG3
hrGqXwpZmcdnR64Tc+ODQH1hFag2IY8Yiq5TABEBAAG0QkV2ZW4gRmluYW5jaWFs
IFRlY2ggKEV2ZW4gRmluYW5jaWFsIFRlY2gpIDx0ZWNoQGV2ZW5maW5hbmNpYWwu
{
"uuid": "b120a2ba-9297-46f3-b190-13b1c6fbcd2c",
"leadUuid": "8bf2da56-8fd9-40c6-ba68-7f1e6cc204cd",
"loanOffers": [
{
"uuid": "9a79f333-ea53-4d88-b432-49c539bef7dc",
"originator": {
"key": "opploans",
"name": "OppLoans",
"description": "<span> <ul> <li>Receive money in your account as soon as the next business day</li> <li>Easy online application process and quick decisions</li> <li>No prepayment fees</li><li>Rated 4.9 out of 5 stars for customer service on Google</li></span>",
@phillro
phillro / gist:1147306
Created August 15, 2011 17:50
Elastica with an authenticated search
<?php
set_include_path(get_include_path() . PATH_SEPARATOR . realpath(dirname(__FILE__) . '/Elastica/lib'));
function elasticsearch_autoload($class) {
$file = str_replace('_', '/', $class) . '.php';
require_once $file;
}
spl_autoload_register('elasticsearch_autoload');
defined('BASE_PATH') || define('BASE_PATH', realpath(dirname(__FILE__)));
var payouts = {
'best-egg':.02,
'prosper' : .015,
'ascend': .02,
'lending-club': .0115,
'avant': .005,
'upstart' : 225,
function calculatePaymentForPrequalifiedOffer(requestedAmount, loanOffer) {
function calcPmnt(amount, apr, months){
var interest = apr / 100 / 12;
var x = Math.pow(1 + interest, months);
var monthly = (requestedAmount*x*interest)/(x-1);
return Math.round(monthly*100)/100;
}
var out = {};
var months
switch(loanOffer.termUnit){
@phillro
phillro / gist:1126819
Created August 5, 2011 02:33
Grails Restclient. Elastic Search with authentication for ElasticSearch HQ
withRest(uri: 'https://esh01.elasticsearchhq.com:9200) {
handler.success = { resp, results ->
return results
}
handler.failure = { resp ->
log.error "Unexpected failure: ${resp.statusLine}"
return false;
}
def response = post(
@phillro
phillro / gist:8656128
Created January 27, 2014 20:00
fuck you slick
select x2.x3, x2.x4, x2.x5, x2.x6, x2.x7, x2.x8, x2.x9, x2.x10, x2.x11, x2.x12, x2.x13, x2.x14, x2.x15, x2.x16, x2.x17, x2.x18, x2.x19, x2.x20, x2.x21, x2.x22, x2.x23, x2.x24, x2.x25, x2.x26, x27.x28, x27.x29, x27.x30, x27.x31, x27.x32 from (select x33.x34 as x3, x33.x35 as x4, x33.x36 as x5, x33.x37 as x6, x33.x38 as x7, x33.x39 as x8, x33.x40 as x9, x33.x41 as x10, x33.x42 as x11, x33.x43 as x12, x33.x44 as x13, x33.x45 as x14, x33.x46 as x15, x47.x48 as x16, x47.x49 as x17, x47.x50 as x18, x47.x51 as x19, x47.x52 as x20, x47.x53 as x21, x47.x54 as x22, x47.x55 as x23, x47.x56 as x24, x47.x57 as x25, x47.x58 as x26 from (select x59.x60 as x34, x59.x61 as x35, x59.x62 as x36, x59.x63 as x37, x59.x64 as x38, x59.x65 as x39, x59.x66 as x40, x59.x67 as x41, x68.x69 as x42, x68.x70 as x43, x68.x71 as x44, x68.x72 as x45, x68.x73 as x46 from (select x74."id" as x60, x74."name" as x61, x74."script" as x62, x74."model_type" as x63, x74."date_range_low" as x64, x74."date_range_high" as x65, x74."created_at" as x66,
def getOneStuffWithThings(stuffId: Long, accountId: Long):ParentCaseClass = {
val suffWithThings = db.withSession {
implicit s: Session =>
val q1 = Stuff
.filter(_.id === stuffId)
.filter(_.accountId === accountId)
.leftJoin(OtherRelatedStuff).on(_.otherRelatedStuffId === _.id)
.leftJoin(MoreRelatedStuff).on(_._2.moreRelatedStuffId === _.id)
.map {
case ((stuff, otherRelatedStuff), MoreRelatedStuff) => {