Skip to content

Instantly share code, notes, and snippets.

@vncsna
vncsna / bash_strict_mode.md
Created June 6, 2021 01:59 — forked from mohanpedala/bash_strict_mode.md
set -e, -u, -o, -x pipefail explanation

set -e, -u, -o, -x pipefail

The set lines

  • These lines deliberately cause your script to fail. Wait, what? Believe me, this is a good thing.
  • With these settings, certain common errors will cause the script to immediately fail, explicitly and loudly. Otherwise, you can get hidden bugs that are discovered only when they blow up in production.
  • set -euxo pipefail is short for:
set -e
set -u
@ChristopherDavenport
ChristopherDavenport / LRUCache.scala
Last active May 7, 2024 15:38
LRUCache Implementation
// import cats._
import cats.effect._
import cats.effect.concurrent.{Ref, Semaphore}
import cats.effect.implicits._
import cats.implicits._
import scala.concurrent.duration._
import scala.collection.immutable.Map
import io.chrisdavenport.mapref.MapRef
// import io.chrisdavenport.mapref.implicits._
@gatorcse
gatorcse / StreamMerger.scala
Last active January 14, 2023 21:09
Merging two already sorted fs2 streams, with a sortBy function.
import cats._
import cats.implicits._
import cats.effect._
import cats.effect.implicits._
import fs2._
class StreamMerger[F[_]] {
def priorityOrderBy[A, B: Order](s1: Stream[F, A], s2: Stream[F, A])(f: A => B): Stream[F, A] = {
def go(p1: Stream.StepLeg[F, A], p2: Stream.StepLeg[F, A]): Pull[F, A, Unit] = {
@Fristi
Fristi / DiffableDerivation.scala
Created November 28, 2018 07:37
specs2 `Diffable` magnolia derivation
import magnolia.{CaseClass, Magnolia, SealedTrait}
import org.specs2.matcher.describe._
import scala.language.experimental.macros
object DiffableDerivation {
/** binds the Magnolia macro to this derivation object */
implicit def genDiffable[T]: Diffable[T] = macro Magnolia.gen[T]
@mmellison
mmellison / grpc_asyncio.py
Last active August 6, 2024 01:23
gRPC Servicer with Asyncio (Python 3.6+)
import asyncio
from concurrent import futures
import functools
import inspect
import threading
from grpc import _server
def _loop_mgr(loop: asyncio.AbstractEventLoop):
@vpontis
vpontis / copy.py
Last active January 11, 2024 18:59
Copy to clipboard from iPython on Mac OS X
"""
Add copy to clipboard from IPython!
To install, just copy it to your profile/startup directory, typically:
~/.ipython/profile_default/startup/
Example usage:
%copy hello world
# will store "hello world"

Moved

Now located at https://github.com/JeffPaine/beautiful_idiomatic_python.

Why it was moved

Github gists don't support Pull Requests or any notifications, which made it impossible for me to maintain this (surprisingly popular) gist with fixes, respond to comments and so on. In the interest of maintaining the quality of this resource for others, I've moved it to a proper repo. Cheers!

@mattcarp
mattcarp / unicode_fuzz.py
Created July 24, 2012 22:09
Generates a random length string of non-control Unicode characters
#!/usr/bin/python
import random
import unicodedata
def unicode_fuzz(lower_limit=0, upper_limit=60):
unicode_glyphs = ''.join(
unichr(char)
for char in xrange(65533)
# use the unicode categories that don't include control codes
@gcollazo
gcollazo / Backbone.sync_csrftoken.js
Created September 25, 2011 14:56
This is what I did to insert the CSRF token in backbone requests. This works with django.
var oldSync = Backbone.sync;
Backbone.sync = function(method, model, options){
options.beforeSend = function(xhr){
xhr.setRequestHeader('X-CSRFToken', CSRF_TOKEN);
};
return oldSync(method, model, options);
};