Skip to content

Instantly share code, notes, and snippets.

@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]
@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 / 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 / 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