Skip to content

Instantly share code, notes, and snippets.

@danveloper
danveloper / html5-thumbnail-iframe.html
Created September 27, 2012 18:59
HTML5 Thumbnail Processing in IFRAME
<!DOCTYPE html>
<html>
<head>
<script>
window.onload = function() {
// Must be server-side images; non-origin images will result in a security exception
var images = ["img.jpg"];
for (var i=0;i<images.length;i++) {
thumbnailify(images[i]);
@danveloper
danveloper / api_adapter.py
Created December 22, 2023 14:16
Translate Llama2-7B-functions output model to OAI JSON spec
from fastapi import FastAPI, Request
import json
import requests
"""
{
"messages": [
{
"content": "you are immensely smart function AI",
"role": "system"

Ratpack Production Tunings

# cat /etc/security/limits.conf

*         hard    nofile      500000
*         soft    nofile      500000
root      hard    nofile      500000
root      soft    nofile      500000
/**
* The `Promise#map` method is used to retrieve
* a value asynchronously (via a `Promise`) and
* transform it synchronous to a new value.
*/
class MappingSpec extends Specification {
@AutoCleanup
ExecHarness harness = ExecHarness.harness()
@danveloper
danveloper / MainGroovy.groovy
Created June 11, 2015 15:52
Ratpack 0.9.17 WebSocket Streaming
import com.google.inject.Inject
import com.google.inject.Scopes
import org.reactivestreams.Publisher
import ratpack.exec.ExecController
import ratpack.form.Form
import ratpack.func.Function
import ratpack.groovy.Groovy
import ratpack.guice.Guice
import ratpack.server.RatpackServer
import ratpack.server.ServerConfig
@danveloper
danveloper / convert.sh
Last active December 5, 2018 18:51
Java to Groovy converter in bash!!
#!/bin/sh
find . -iname "*.java" -exec sed s/\;$// {} \;
@danveloper
danveloper / build.gradle
Created October 28, 2018 11:15
adding ignore-exceptions-ast to Gradle build
apply plugin: 'groovy'
apply plugin: 'idea'
repositories {
maven { url "https://dl.bintray.com/danveloper/maven" }
}
dependencies {
compile 'com.github.danveloper.ast:ignore-exceptions-ast:1.0.0-rc-2'
}
@danveloper
danveloper / a.groovy
Last active October 11, 2018 18:11
Standalone Ratpack Groovy 0.9.13
@GrabResolver(name='netty', root='http://clinker.netty.io/nexus/content/repositories/snapshots')
@Grab('io.ratpack:ratpack-groovy:0.9.13-SNAPSHOT')
import ratpack.handling.Handler
import ratpack.server.*
RatpackServer.of { spec -> spec
.config(ServerConfig.noBaseDir())
.handler {
{ ctx -> ctx.render "Hello World!" } as Handler
}
@danveloper
danveloper / ratpack.md
Created January 10, 2015 19:14
Ratpack as of 0.9.13

build.gradle

buildscript {
  repositories {
    jcenter()
    maven { url "http://oss.jfrog.org/oss-snapshot-local" }
    maven { url "http://clinker.netty.io/nexus/content/repositories/snapshots" }
  }
  dependencies {
@danveloper
danveloper / urlshortener.groovy
Created November 8, 2012 21:55
The 48-Line Volatile URL Shortener
import java.net.ServerSocket
def socket = 8281, password = "danrulz"
enum Database {
INSTANCE;
def table = [:]
def shortCodeTable = [:]
def insert = { String url ->
Sequence.INSTANCE.counter++
def id = Sequence.INSTANCE.counter
def shortCode = new BigInteger(id).toString(36)+BigInteger.valueOf(Math.round(Math.random()*1000)).toString(36)