Skip to content

Instantly share code, notes, and snippets.

View EdgeCaseBerg's full-sized avatar
📉
Wondering why Github added statuses instead of something useful

Ethan Eldridge EdgeCaseBerg

📉
Wondering why Github added statuses instead of something useful
View GitHub Profile
@pralkarz
pralkarz / case-study.md
Last active April 20, 2025 14:39
Case study: investigating and improving an ESLint rule's (`eslint-plugin-n/prefer-node-protocol`) performance

Note

My approach contains some guesswork and might lack depth in a few areas. If you notice any mistakes or opportunities for improvement, the easiest way to reach out to me is either commenting under this Gist, or writing directly on Discord where I have the same nickname as here.

The problem

After profiling ESLint rules' performance in the Svelte repository, Ben McCann noticed that the n/prefer-node-protocol rule takes almost 50% of the total linting time: eslint-community/eslint-plugin-n#404. As with most issues I tackle, I wanted to start by reproducing the result, so I cloned the Svelte repository, installed the dependencies, and ran pnpm build.

Initially, I tried to check the performance in a more granular way with the --stats option (available in ESLint 9+, which is used in this particular project). This has proven unfeasible though as even when outputting JSON and redirecting stdo

@Faheetah
Faheetah / Jenkinsfile.groovy
Last active April 10, 2025 01:40
Jenkinsfile idiosynchrasies with escaping and quotes
node {
echo 'Results included as an inline comment exactly how they are returned as of Jenkins 2.121, with $BUILD_NUMBER = 1'
echo 'No quotes, pipeline command in single quotes'
sh 'echo $BUILD_NUMBER' // 1
echo 'Double quotes are silently dropped'
sh 'echo "$BUILD_NUMBER"' // 1
echo 'Even escaped with a single backslash they are dropped'
sh 'echo \"$BUILD_NUMBER\"' // 1
echo 'Using two backslashes, the quotes are preserved'
sh 'echo \\"$BUILD_NUMBER\\"' // "1"
@rrodseth
rrodseth / UnfoldPages.scala
Last active June 14, 2021 18:36
Create akka-stream Source from a pagination, using Source.unfoldAsync
// Inspired by a tweet from @trautonen 1/13/2016
// Use Source.unfoldAsync to turn paginated database results into an akka-streams Source
// unfold is the inverse of fold
case class Page[T](pageNumber:Long, totalPages:Long, contents:List[T])
case class Thing(id: Long, name: String = "foo")
val totalPages = 5 //
val pageSize = 3
@haywood
haywood / DBObjectJsValue.scala
Created April 8, 2015 03:50
Casbah DBObject/Play JsValue Conversion
/**
* This was something I explored today.
* The approach is fundamentally flawed for a couple of reasons.
*
* 1. play JSON serializes dates to strings,
* but they are better represented as timestamps or ISODates in mongo.
*
* 2. ObjectId's cannot be round-tripped, since they turn into JSON
* strings on the way out.
*
@freiguy1
freiguy1 / Grunt.scala
Created March 20, 2015 04:00
Using grunt to compile runtime assets in Play Framework app
import sbt._
import Keys._
import java.net._
import java.io.File
import play.PlayRunHook
/*
Grunt runner should be in project directory to be picked up by sbt
*/
object Grunt {
@koelling
koelling / gist:ef9b2b9d0be6d6dbab63
Last active December 30, 2024 15:55
CVE-2015-0235 (GHOST) test code
#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#define CANARY "in_the_coal_mine"
struct {
char buffer[1024];
@davegurnell
davegurnell / anorm.scala
Last active April 10, 2025 06:37
A short guide to Anorm
/*
Overview
--------
To run a query using anorm you need to do three things:
1. Connect to the database (with or without a transaction)
2. Create an instance of `anorm.SqlQuery` using the `SQL` string interpolator
3. Call one of the methods on `SqlQuery` to actually run the query
@chaotic3quilibrium
chaotic3quilibrium / DIY Scala Enumeration - README.txt
Last active September 13, 2020 22:20
DIY Scala Enumeration (closest possible Java Enum equivalent with guaranteed pattern matching exhaustiveness checking)
README.txt - DIY Scala Enumeration
Copyright (C) 2014-2016 Jim O'Flaherty
Overview:
Provide in Scala the closest equivalent to Java Enum
- includes decorating each declared Enum member with extended information
- guarantees pattern matching exhaustiveness checking
- this is not available with scala.Enumeration
ScalaOlio library (GPLv3) which contains more up-to-date versions of both `org.scalaolio.util.Enumeration` and `org.scalaolio.util.EnumerationDecorated`:
@fancellu
fancellu / ExceptionDig.scala
Last active December 13, 2023 06:07
Various ways to recurse down Exception causes in Scala
// Using vars, lots of local mutation
def getThemVar(th:Throwable)={
var now=th
var li=List[Throwable](now)
var cause=now.getCause
while (cause!=null){
li=cause::li
now=cause
cause=now.getCause
}