Skip to content

Instantly share code, notes, and snippets.

View nightscape's full-sized avatar

Martin Mauch nightscape

View GitHub Profile
@nightscape
nightscape / simple_cors_server.py
Last active January 30, 2021 22:31 — forked from acdha/simple_cors_server.py
Python 3: serve the current directory as HTTP while setting CORS headers for XHR debugging
#!/usr/bin/env python3
# encoding: utf-8
"""Use instead of `python3 -m http.server` when you need CORS"""
from http.server import HTTPServer, SimpleHTTPRequestHandler
class CORSRequestHandler(SimpleHTTPRequestHandler):
def end_headers(self):
self.send_header('Access-Control-Allow-Origin', '*')
@nightscape
nightscape / zmv-examples.md
Last active February 28, 2023 20:39 — forked from niksmac/zmv-examples.md
ZMV-Examples (require autoload zmv)

rename a section of a filename, i. e. example.1.{txt,conf,db} or 12345.1.{wav,ogg,mp3} and change the 1 to a 2 in the filename while preserving the rest of it.

  zmv -n '(*.)(<->)(.[^.]#)' '$1$(($2+1))$3' # would rename x.0001.y to x.2.y.
  zmv -n '(*.0#)(<->)(.[^.]#)' '$1$(($2+1))$3'

Rename files to lower case

  $ zmv '*' '${(L)f}'
@nightscape
nightscape / fields.sc
Created April 3, 2020 15:48 — forked from danslapman/fields.sc
Get field names of case class using shapeless
import $ivy.`com.chuusai::shapeless:2.3.3`
import shapeless._
trait Fields[T] {
def fields: List[String]
override def toString: String = fields.mkString(", ")
}
object Fields extends LabelledProductTypeClassCompanion[Fields] {
def apply[T](fs: List[String]): Fields[T] = new Fields[T] {
override def fields: List[String] = fs
import cats.effect._
import scala.concurrent.{ExecutionContext, Future}
class FutureConcurrentEffect()(implicit ec: ExecutionContext) extends FutureEffect with ConcurrentEffect[Future] {
def start[A](fa: Future[A]): Future[Fiber[Future, A]] = Future.successful {
FutureFiber(fa)
}
def racePair[A, B](fa: Future[A], fb: Future[B]): Future[Either[(A, Fiber[Future, B]), (Fiber[Future, A], B)]] = ???
package shiplis
import shapeless._, poly._, ops.hlist._
object MapWith
{
object Apply
extends Poly2
{
implicit def c[A, B, R, Tail <: HList, F <: Poly2]
@nightscape
nightscape / Main.scala
Last active January 22, 2018 17:36 — forked from anonymous/Main.scala
Scala.jsFiddle gist
import com.google.appsscript.adwords._
import com.google.appsscript.base.Logger
import com.google.appsscript.spreadsheet._
/**
* This is an example app for Apps Scaripped using Google Spreadsheet
*/
object AppsScarippedMain extends js.JSApp{
def main(): Unit = {
val adsIterator = AdWordsApp.ads()
@nightscape
nightscape / Gui.scala
Created November 29, 2012 01:44 — forked from fnumatic/Gui.scala
Simple Swing Application with scala.react * github.com/ingoem/scala-react
import MySwingDomain._
object Gui extends ReactiveSwingApp {
val button = new MyButton("test")
def top = new MainFrame {
contents = new FlowPanel {
contents += button
}
}
@nightscape
nightscape / Gui.scala
Created November 29, 2012 01:44 — forked from fnumatic/Gui.scala
Simple Swing Application with scala.react * github.com/ingoem/scala-react
import MySwingDomain._
object Gui extends ReactiveSwingApp {
val button = new MyButton("test")
def top = new MainFrame {
contents = new FlowPanel {
contents += button
}
}