Skip to content

Instantly share code, notes, and snippets.


Paul Daniels paulpdaniels

  • Singapore
View GitHub Profile
paulpdaniels / LogZIOCompat.scala
Created December 2, 2022 07:01
A ZIO2 compatible LogStage encoding
View LogZIOCompat.scala
package compat
import izumi.functional.mono.SyncSafe
import izumi.fundamentals.platform.language.CodePositionMaterializer
import izumi.logstage.api.Log
import izumi.logstage.api.Log.{CustomContext, Entry, Level, LogArg, Message}
import izumi.logstage.api.logger.AbstractLogger
import izumi.logstage.api.rendering.AnyEncoded
import izumi.logstage.macros.LogIOMacroMethods._
import logstage.UnsafeLogIO.UnsafeLogIOSyncSafeInstance
View ApplicationLoader.scala
import zio._
class Components(context: ApplicationLoader.Context)
extends BuiltInComponentsFromContext(context) {
// Initialize the layer
val appLayer = ++ ++
// Create a new runtime backed by the application layer
paulpdaniels / EntityResolver.scala
Created September 23, 2020 16:31
Sangria Federation
View EntityResolver.scala
package sangria.federation
import play.api.libs.json.{JsError, JsObject, JsSuccess, Reads}
import sangria.schema.{LeafAction, ObjectLikeType, Value}
trait EntityResolver[Ctx] {
def typename: String
def resolve(obj: JsObject): LeafAction[Ctx, Option[Any]]
paulpdaniels / Example.scala
Last active November 4, 2022 15:43
An example of the relay node specification with Caliban
View Example.scala
object Example extends GenericSchema[Clock] {
implicit val extractorStrategy: ExtractorStrategy = ExtractorStrategy.hyphen
case class User(id: String)
case class Team(id: String)
case class NodeArg(id: String)
val userSchema = gen[User]
val teamSchema: Schema[Clock, Team] = gen[Team]
paulpdaniels / marketing_example.html
Last active April 14, 2016 17:36
Example a block
View marketing_example.html
<a href="your_link_goes_here" style="float: right;">
<img src="img_src"/>
View bad_encryption.js
var key = "ZzLlQqUuAa1RrBb2YyCc3XxDd4WwEe5VvFf6TtGg7SsHh8PpIi9JOoj0KkMmNn";
var cardtype = document.studio_form.CARD_TYPE.value;
var cardnumber = document.studio_form.CARD_NUMBER.value;
var carddate = document.studio_form.CARD_DATE.value;
var cardname = document.studio_form.CARD_NAME.value;
var cardaddress = document.studio_form.CARD_ADDRESS.value
+ ", " + document.studio_form.CARD_CITY.value
+ ", " + document.studio_form.CARD_STATE.value
+ ", " + document.studio_form.CARD_ZIP.value
+ " " + document.studio_form.CARD_COUNTRY.value;
paulpdaniels / UsingLatest.cs
Last active August 29, 2015 14:06
Reactive Observable for UsingLatest
View UsingLatest.cs
/// <summary>
/// Creates an observable that will attach the latest value from a second source observable for each value.
/// </summary>
/// <typeparam name="TSource1">The source observable</typeparam>
/// <typeparam name="TSource2">The attached observable</typeparam>
/// <typeparam name="TResult">The result type</typeparam>
/// <param name="source1">The type of the incoming observable</param>
/// <param name="source2">The type of the attached observable</param>
/// <param name="resultSelector"></param>
/// <returns>An observable that is the result of applying <paramref name="resultSelector"/> on the two observables</returns>
paulpdaniels / IndexOf.cs
Created August 21, 2014 19:54
Linq fast indexOf
View IndexOf.cs
namespace System.Linq {
public static class EnumerableExtensions {
public static int IndexOf<T1>(this IEnumerable source, Func<T1, bool> predicate) {
var enumerator = source.GetEnumerator();
bool lastEval = false;
int index = -1;
paulpdaniels / ZipEach.cs
Created August 18, 2014 20:50
Linq enumerate multiple collections simultaneously
View ZipEach.cs
public static class EnumerableExtensions
/// <summary>
/// Enumerates over two sequences simulateneously and performs the action on both
/// </summary>
/// <typeparam name="T1"></typeparam>
/// <typeparam name="T2"></typeparam>
/// <param name="source1"></param>
/// <param name="source2"></param>
/// <param name="eacher">The action which takes a value from each sequence</param>
paulpdaniels / ConcurrentPriorityQueue.cs
Last active August 29, 2015 14:04
A simple Scheduler for use in Xna Games
View ConcurrentPriorityQueue.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
namespace System.Collections.Concurrent
/// <summary>Provides a thread-safe priority queue data structure.</summary>
/// <typeparam name="TKey">Specifies the type of keys used to prioritize values.</typeparam>