Skip to content

Instantly share code, notes, and snippets.

@mrdziuban
mrdziuban / PsySH_with_Yii.md
Last active August 21, 2019 10:20
How to use PsySH with a Yii application

Using PsySH (GitHub) as the Yii shell

  • Issue the following commands from the command line in your Yii application directory:
    • chmod +x shell
    • mkdir extensions/yiishell
    • wget -O extensions/yiishell/psysh psysh.org/psysh
    • chmod +x extensions/yiishell/psysh
  • Copy the file init.php below to extensions/yiishell/init.php and update any paths to work with your application configuration
  • Copy the file config.php below to extensions/yiishell/config.php. Change or add to the config array with the options you'd like to use (available options)
  • Now you can start PsySH with the command extensions/yiishell/psysh extensions/yiishell/init.php --config extensions/yiishell/config.php
@mrdziuban
mrdziuban / version_match.rb
Last active May 26, 2016 15:49
rubygem version match
exit(Gem::Dependency.new('', "~> #{ARGV[0]}").match?('', ARGV[1]) ? 0 : 1)
@mrdziuban
mrdziuban / setup.md
Last active November 17, 2016 17:32
Ruby script to pretty print Shapeless record errors

Setup

  • Download shapeless_errors.rb to your computer

  • Make it executable:

    chmod +x /path/to/shapeless_errors.rb

  • Install the terminal-table gem:

gem install terminal-table

@mrdziuban
mrdziuban / typescript_spread.md
Last active January 13, 2017 17:55
TypeScript spread operators

The goal here is to create an array of [0, 1, 2, 3, 4]. Every "Working ES6" column below accomplishes this. The first example fails to compile in TypeScript. The second example compiles and works, but throws errors in IE. The third example compiles, but does not achieve the desired functionality. The last example works as expected (it was found in the comments of Microsoft/TypeScript#8856).

Working ES6 TypeScript Compiled JS Result
[...Array(5).keys()] error TS2461: Type 'IterableIterator' is not an array type. n/a n/a
Array.from(Array(5).keys()) Array.from(Array(5).keys()) Array.from(Array(5).keys()) [0, 1, 2, 3, 4], but does not work in IE
[...Array(5)].map((_, i) => i) [...Array(5)].map((_: any, i: number) => i) Array(5).slice().map(function (_, i) { return i; }) [undefined, undefined, undefined, undefined, undefined]
elixirscript ':console.log("test")' --elixir
@mrdziuban
mrdziuban / scala_repl.rb
Last active March 6, 2018 07:18
Start a Scala REPL with the highest version of each jar in $HOME/.ivy2/cache on the classpath
#!/usr/bin/env ruby
################################################################################
# #
# Starts a Scala REPL with the highest version of each jar in #
# $HOME/.ivy2/cache on the classpath. #
# #
# See below for installation instructions #
# #
################################################################################
@mrdziuban
mrdziuban / first_start.log
Created December 30, 2017 13:09
calibre-web logs
,----,
,/ .`|
,` .' : .--.--. ,----, ,-.
; ; // / '. .' .' \ ,--/ /|
.'___,/ ,'| : /`. / ,----,' |,--. :/ |
| : | ; | |--` | : . ;: : ' /
; |.'; ; | : ;_ ; |.' / | ' /
`----' | | \ \ `. `----'/ ; ' | :
' : ; `----. \ / ; / | | \
| | ' __ \ \ | ; / /-, ' : |. \
@mrdziuban
mrdziuban / TestTypify.scala
Last active January 3, 2018 15:35
shapeless implicit LeftFolder resolution
import $ivy.`com.chuusai::shapeless:2.3.3`
// import $ivy.`com.chuusai::shapeless:2.3.4-SNAPSHOT`
import $ivy.`org.scalaz::scalaz-core:7.2.17`
interp.repositories() ++= Seq(coursier.MavenRepository("https://dl.bintray.com/bondlink/Typify"))
import $ivy.`typify::typify:2.4.1`
import shapeless.{::, HNil}
import shapeless.syntax.singleton._
@mrdziuban
mrdziuban / FoldLeft.scala
Last active January 3, 2018 23:50
Simple shapeless foldLeft
import shapeless.{::, HList, HNil, Poly2}
import shapeless.ops.hlist.Prepend
import shapeless.record._
import shapeless.syntax.singleton._
val h = 1 :: "foo" :: true :: HNil
object withoutAnnotation extends Poly2 {
implicit def id[Acc <: HList, A, Res <: HList](
implicit pp: Prepend.Aux[Acc, A :: HNil, Res]) =
@mrdziuban
mrdziuban / CsvDerivation.scala
Last active May 23, 2018 12:02
Incorrect behavior with type class derivation macro
import scala.language.experimental.macros
import scala.reflect.macros.blackbox.Context
trait Csv[A] { def apply(a: A): Seq[String] }
object Csv {
implicit def deriveCsv[A]: Csv[A] = macro CsvMacro.csvImpl[A]
implicit val csvStr: Csv[String] = new Csv[String] { def apply(s: String) = Seq(s) }
implicit def csvSeq[A](implicit ca: Csv[A]): Csv[Seq[A]] = new Csv[Seq[A]] {
def apply(a: Seq[A]) = a.flatMap(ca(_))