Skip to content

Instantly share code, notes, and snippets.

@xuwei-k
xuwei-k / Converter.scala
Last active May 17, 2021 20:38
Google Cloud Functions with Scala unfiltered
package unfiltered_cloud_function
import com.google.cloud.functions.{HttpFunction, HttpRequest, HttpResponse}
import java.io.OutputStream
import scala.jdk.CollectionConverters._
import java.util.Collections
object Converter {
def request(req: HttpRequest): unfiltered.request.HttpRequest[HttpRequest] =
new unfiltered.request.HttpRequest[HttpRequest](req) {
@fabiolimace
fabiolimace / UUIDv6.sql
Last active July 7, 2024 23:58
Functions for generating UUIDv6 and UUIDv7 on PostgreSQL
/*
* MIT License
*
* Copyright (c) 2023-2024 Fabio Lima
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
@jed204
jed204 / cloudbuild.yaml
Created October 30, 2019 05:36
Google Cloud Build Maven Build with Cache
steps:
# Grab cached M2 repo
- name: gcr.io/cloud-builders/gsutil
id: Get M2 Cache
args: ['cp', 'gs://BUCKET_NAME/m2.tar.gz', 'm2.tar.gz']
# See https://github.com/GoogleCloudPlatform/cloud-builders-community to get the tar command
- name: gcr.io/PROJECT_ID/tar
id: Expand M2 Cache
args: ['xpzf', 'm2.tar.gz']
# Optional, we had some extra settings to include

doobie experiment - postgres NOTIFY as scalaz-stream

One of the cool things PostgreSQL gives you is a simple notification system that you can use to let clients know that something interesting has happened. For instance you can set up rules that broadcast notifications when a table is updated, and client applications can update displays in response. The JDBC driver provides access to this API so I thought I would see what it would look like in doobie.

The program below constructs a Process[ConnectionIO, PGNotification] that registers for events, polls for them periodically (this is the best we can do with current driver support), and unregisters when the stream terminates for any reason. We use a Transactor to replace ConnectionIO with Task which gives us something we can actually run.

package doobie.example

import doobie.imports._
@aryairani
aryairani / AsyncHttpTask.scala
Last active August 29, 2015 14:12
Rewritten AyncHttpClient example for Tim
/**
* Created by arya on 1/2/15.
*/
/*
scalaVersion := "2.11.4"
libraryDependencies += "com.ning" % "async-http-client" % "1.9.3"
libraryDependencies += "org.scalaz" %% "scalaz-concurrent" % "7.1.0"
package com.rr.experiment
import org.specs2.ScalaCheck
import org.specs2.mutable._
import org.scalacheck._
import scalaz._
import scodec._

Reading SBT Credentials from OS X Keychain

In the following, replace the REPO_NAME value with the natural-language name of your repository, replace REPOSITORY with the domain name (e.g. repo1.maven.org) and replace USERNAME with your repository user.

credentials += {
  val Password = """.*password: "([^"]+)".*""".r
  var lines: String = ""
  val logger = new ProcessLogger {
 def info(s: => String) = {}
@nickjacob
nickjacob / systemd-prblm.service
Last active March 17, 2023 16:11
execute arbitrary bash code/variable substitution in systemd units
[Unit]
Description=Demonstrate Bash
[Service]
ExecStartPre=/usr/bin/bash -c "/usr/bin/systemctl set-environment MYVAR=$(( 2 + 2 ))"
ExecStart=/usr/bin/echo "2 + 2 = ${MYVAR}"
@jwalton
jwalton / RickshawGraph.md
Last active July 30, 2021 02:35
Rickshaw Graph is a drop in replacement for Dashing's graph

Graphing Widget

The graphing widget shows graphs using the Rickshaw graphing library. The names of data fields should be (vaguely) familiar if you've used Rickshaw before.

It's recommended that you replace the /assets/javascripts/rickshaw.min.js from your dashboard with the latest from here.

Supported HTML data fields

@CMCDragonkai
CMCDragonkai / angularjs_directive_attribute_explanation.md
Last active November 29, 2023 15:35
JS: AngularJS Directive Attribute Binding Explanation

AngularJS Directive Attribute Binding Explanation

When using directives, you often need to pass parameters to the directive. This can be done in several ways. The first 3 can be used whether scope is true or false. This is still a WIP, so validate for yourself.

  1. Raw Attribute Strings

    <div my-directive="some string" another-param="another string"></div>