Skip to content

Instantly share code, notes, and snippets.

@psttf
psttf / concatenate
Last active December 20, 2015 06:39
Concatenates all files in current directory and subdirectories, inserting filename before each new file. Set to process only .scala files by default.
import java.io.File
import scala.io._
import scala.util.matching.Regex
def recursiveListFiles(f: File, r: Regex): Array[File] = {
val these = f.listFiles
val good = these.filter(f => r.findFirstIn(f.getName).isDefined)
good ++ these.filter(_.isDirectory).flatMap(recursiveListFiles(_,r))
}
@psttf
psttf / MatchTypes.scala
Last active December 28, 2015 18:29
Find values of the same types in HList
import shapeless._
import poly._
import shapeless.ops.hlist.FlatMapper
object am {
/**
* A type class that helps us partially apply a polymorphic binary function
* to some value and map the resulting function (which of course isn't
* literally a Poly1) over an HList.
@psttf
psttf / ConstZipper.scala
Created November 25, 2013 11:50
ConstZipper zips an HList with a constant value
import shapeless._
object cz {
trait ConstZipper[L <: HList, C] extends DepFn2[L, C] { type Out <: HList }
object ConstZipper {
type Aux[L <: HList, C, Out0 <: HList] =
ConstZipper[L, C] { type Out = Out0 }
import shapeless._; import syntax.singleton._; import record._
object os {
trait OptionSelector[L <: HList, K] {
type Out
def apply(l : L): Out
}
trait LowPriorityOptionSelector {
@psttf
psttf / eeeee.sc
Created December 23, 2014 13:49
Projection of one shapeless extensive record to another. Results in a record that contains the same fields in the same order. Possibilities of mapping different case classes (via LabelledGeneric) are also included.
import shapeless._
import shapeless.ops.hlist.Tupler
import syntax.singleton._
import record._
object o {
trait Projection[F <: HList, L <: HList] extends DepFn1[L] { type Out <: HList}
object Projection{
implicit def hnil[L <: HList] = new Projection[HNil, L]{
override type Out = HNil
Welcome to Scala version 2.11.7 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_45).
Type in expressions to have them evaluated.
Type :help for more information.
scala> val i = 123 // значение для сравнения
i: Int = 123
scala> def if_i_1(x: Int) = x match { case i => true; case _ => false } // Scala нас предупреждает, что притаком определении сравнение проводиться не будет!
<console>:10: warning: patterns after a variable pattern cannot match (SLS 8.1.1)
def if_i_1(x: Int) = x match { case i => true; case _ => false }
@psttf
psttf / methodUpdate.js
Created May 6, 2016 19:28
Method update in JavaScript
// from repl.it
function myClass() {
this.uniqueTask = function() {
return 2
}
}
var obj = new myClass();
obj.uniqueTask = function() {
import cats.Monad
import scala.concurrent.Future
import scala.language.higherKinds
import scala.concurrent.ExecutionContext.Implicits.global
object Swap {
def apply[F[_], A](l: List[F[A]])(implicit m: Monad[F]): F[List[A]] =
@psttf
psttf / ConnectRemoteDesktopusingKeePassCredentials
Last active January 11, 2021 08:11 — forked from janikvonrotz/ConnectRemoteDesktopusingKeePassCredentials
Connect Remote Desktop using KeePass Credentials#KeePass#EmbededPost via URL Override
cmd://cmd /c "cmdkey /generic:TERMSRV/{URL:HOST} /user:{USERNAME} /pass:"{PASSWORD}" && mstsc /v:{URL:RMVSCM} && cmdkey /delete:TERMSRV/{URL:RMVSCM}"
@psttf
psttf / FlipFlopWheel.ps
Last active October 24, 2017 11:27
PowerShell one-liner to set reverse scrolling (flip wheel or reverse scrolling)
Get-ItemProperty HKLM:\SYSTEM\CurrentControlSet\Enum\HID\*\*\Device` Parameters FlipFlopWheel -EA 0 | ForEach-Object { Set-ItemProperty $_.PSPath FlipFlopWheel 1 }