Skip to content

Instantly share code, notes, and snippets.

View glaforge's full-sized avatar

Guillaume Laforge glaforge

View GitHub Profile
@glaforge
glaforge / CallGemma.java
Created April 2, 2024 11:34
Ollama conditional image creation
package gemini.workshop;
import com.github.dockerjava.api.model.Image;
import dev.langchain4j.model.chat.ChatLanguageModel;
import dev.langchain4j.model.ollama.OllamaChatModel;
import org.testcontainers.DockerClientFactory;
import org.testcontainers.ollama.OllamaContainer;
import org.testcontainers.utility.DockerImageName;
import java.io.IOException;
@glaforge
glaforge / CallGemma.java
Created April 2, 2024 08:45
Conditionally create the derived container if it hasn't been already created
package gemini.workshop;
import dev.langchain4j.model.chat.ChatLanguageModel;
import dev.langchain4j.model.ollama.OllamaChatModel;
import org.testcontainers.ollama.OllamaContainer;
import org.testcontainers.utility.DockerImageName;
import java.io.IOException;
public class CallGemma {
@glaforge
glaforge / slugifyTest.groovy
Created January 4, 2024 01:25
Creating slugs from any text (including in non-latin languages) using the Slugify library and ICU for transliteration
@Grab('com.ibm.icu:icu4j')
@Grab('com.github.slugify:slugify')
import com.github.slugify.*
var slugify = Slugify.builder()
.transliterator(true)
.locale(Locale.ENGLISH)
.build()
println slugify.slugify("Un bel été où l'hôtel François à rebours des îles de Noël tenait tête")
@Grab("com.google.openlocationcode:openlocationcode:1.0.4")
import com.google.openlocationcode.OpenLocationCode
// Eiffel Tower
def (lat, lon) = [48.8584, 2.29447]
def eiffelTowerPlusCode = OpenLocationCode.encode(lat, lon)
println "Eiffel Tower +code: ${eiffelTowerPlusCode}"
def decoded = OpenLocationCode.decode('8FW4V75V+9Q')
{
"msg": "Hello World!"
}
import java.nio.file.Paths
@Grab('org.jsoup:jsoup:1.15.4')
import org.jsoup.Jsoup
import org.jsoup.safety.Safelist
@Grab('org.apache.commons:commons-lang3:3.12.0')
import static org.apache.commons.lang3.StringUtils.getLevenshteinDistance as levenDist
@Grab('org.codehaus.gpars:gpars:1.2.1')
@glaforge
glaforge / fetchPostsToMD.groovy
Created March 7, 2023 17:40
Transform my old blog posts into Hugo friendly Markdown article documents
@Grab('org.jsoup:jsoup:1.15.4')
import org.jsoup.Jsoup
import org.jsoup.safety.Safelist
@Grab('io.github.furstenheim:copy_down:1.1')
import io.github.furstenheim.*
import java.nio.file.Paths
import java.nio.file.Files
import java.text.SimpleDateFormat
@Controller("/product")
public class ProductController {
@Get
@Status(HttpStatus.OK)
public void index() {
throw Problem.builder()
.withType(URI.create("https://example.org/out-of-stock"))
.withTitle("Out of Stock")
.withStatus(new HttpStatusType(HttpStatus.BAD_REQUEST))
.withDetail("Item B00027Y5QG is no longer available")
HTTP/1.1 403 Forbidden
Content-Type: application/problem+json
Content-Language: en
{
"type": "https://example.com/probs/out-of-credit",
"title": "You do not have enough credit.",
"detail": "Your current balance is 30, but that costs 50.",
"instance": "/account/12345/msgs/abc",
"balance": 30,
@glaforge
glaforge / package.json
Created May 4, 2017 10:29
Code for the Cloud Functions implementation of the demo from Cloud Next San Francisco on extending the Google Assistant with Actions on Google, API.AI and Cloud Functions
https://www.youtube.com/watch?v=7e0RGIul8Kk