Skip to content

Instantly share code, notes, and snippets.

View ASRagab's full-sized avatar
👨‍💻

Ahmad Ragab ASRagab

👨‍💻
View GitHub Profile
@mjambon
mjambon / parallel
Last active March 28, 2024 11:09
bash: Run parallel commands and fail if any of them fails
#! /usr/bin/env bash
#
# Run parallel commands and fail if any of them fails.
#
set -eu
pids=()
for x in 1 2 3; do
@Slakah
Slakah / HttpCaching.scala
Created August 27, 2018 12:42
http4s caching middleware
package com.gubbns
import cats.data.{Kleisli, OptionT}
import cats.effect._
import cats.implicits._
import com.github.blemale.scaffeine.{Cache, Scaffeine}
import org.http4s._
import org.http4s.headers._
import org.http4s.server.Middleware
@kdrakon
kdrakon / Avro4s.scala
Last active December 16, 2022 15:29
Using Avro4s with Confluent Kafka Avro Serializer + Schema Registry
import java.util
import com.sksamuel.avro4s.RecordFormat
import org.apache.avro.generic.GenericRecord
import org.apache.kafka.common.serialization.{Deserializer, Serde, Serializer}
object Avro4s {
implicit class CaseClassSerde(inner: Serde[GenericRecord]) {
def forCaseClass[T](implicit recordFormat: RecordFormat[T]): Serde[T] = {
val caseClassSerializer: Serializer[T] = new Serializer[T] {
@agaro1121
agaro1121 / CommonModels.scala
Created January 9, 2018 18:29
Free Monad vs Tagless Final
case class User(id: Long, name: String, age: Int)
class DatabaseError extends Throwable
case object ErrorFindingUser extends DatabaseError
case object ErrorUpdatingUser extends DatabaseError
case class ErrorDeletingUser(msg: String) extends DatabaseError
@jamtur01
jamtur01 / pre-commit
Created October 18, 2016 21:54
A Terraform validation and formatting pre-commit hook
#!/usr/bin/env bash
set -e
# Formats any *.tf files according to the hashicorp convention
files=$(git diff --cached --name-only)
for f in $files
do
if [ -e "$f" ] && [[ $f == *.tf ]]; then
#terraform validate `dirname $f`
terraform fmt $f
@mphillips
mphillips / nginx-site-config-file.conf
Last active August 16, 2019 14:03
SAML 2.0 Single Sign-On WordPress Plugin Fix for Nginx
# 1) Edit the site's nginx config (/etc/nginx/custom-sites/site-name.conf) to add the lines below.
# 2) Reload nginx: sudo service nginx reload
server {
# existing conf here
# Nginx fix for the SAML 2.0 Single Sign-On plugin.
location ^~ /wp-content/plugins/saml-20-single-sign-on {
location ~ ^(?<script_name>.*?\.php)(?<path_info>/.*)?$ {
include fastcgi_params;
@jpallari
jpallari / Main.scala
Last active February 5, 2024 08:29
Ways to pattern match generic types in Scala
object Main extends App {
AvoidLosingGenericType.run()
AvoidMatchingOnGenericTypeParams.run()
TypeableExample.run()
TypeTagExample.run()
}
class Funky[A, B](val foo: A, val bar: B) {
override def toString: String = s"Funky($foo, $bar)"
}
@hammer
hammer / HelloAvro.scala
Last active October 17, 2022 04:16
Concise example of how to write an Avro record out as JSON in Scala
import java.io.{IOException, File, ByteArrayOutputStream}
import org.apache.avro.file.{DataFileReader, DataFileWriter}
import org.apache.avro.generic.{GenericDatumReader, GenericDatumWriter, GenericRecord, GenericRecordBuilder}
import org.apache.avro.io.EncoderFactory
import org.apache.avro.SchemaBuilder
import org.apache.hadoop.fs.Path
import parquet.avro.{AvroParquetReader, AvroParquetWriter}
import scala.util.control.Breaks.break
object HelloAvro {
anonymous
anonymous / gist:10675250
Created April 14, 2014 19:11
Motion Blur + Chromatic Aberration
// by dave @ beesandbombs.tumblr.com >:)
void setup() {
setup_();
result = new int[width*height][3];
result_ = new int[width*height][3];
}
int[][] result, result_;
float time;