Skip to content

Instantly share code, notes, and snippets.

View ASRagab's full-sized avatar
👨‍💻

Ahmad Ragab ASRagab

👨‍💻
View GitHub Profile
@ASRagab
ASRagab / scastie.scala
Last active October 24, 2017 23:48
Scala Koans?
def last[T](ls: List[T]): T = {
ls match {
case Nil => throw new Exception("No last element of empty list")
case h :: Nil => h
case _ :: tail => last(tail)
}
}
val test = List(2, 4, 7, 3, 100)
last(test)
@ASRagab
ASRagab / bankersQueue.sc
Created February 16, 2018 02:08
Banker's Queue Implementation
object queuesBankers {
import BankersQueue._
case class BankersQueue[+A](sizeFront: Int, front: Stream[A], sizeRear: Int, rear: Stream[A]) {
def enqueue[B >: A](b: B) =
check(BankersQueue(sizeFront,front, sizeRear + 1, b #:: rear))
def dequeue = front match {
case h #:: t => {
val remaining = BankersQueue(sizeFront - 1, t, sizeRear, rear)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Date CaloriesBurned Steps Distance(km) Stairs MinutesAtRest MinutesOfLightActivity MinutesOfModerateActivity MinutesOfIntenseActivity CaloriesBurnedWhileActive MinutesOfSleep MinutesOfBeingAwake NumberOfAwakenings LengthOfRestInMinutes
04/28/2016 4030 25571 19.3 15 606 293 42 129 2711 348 20 9 368
04/29/2016 3442 17528 13.36 15 594 239 8 82 1931 454 48 27 502
04/30/2016 3061 9831 7.3 1 561 414 0 0 1651 347 41 20 388
05/01/2016 3331 14262 10.6 5 666 361 21 41 1937 314 34 23 348
05/02/2016 2989 13236 9.98 12 770 234 8 38 1477 377 33 18 410
05/03/2016 3796 18588 14.13 16 599 275 49 79 2360 406 21 8 427
05/04/2016 3525 16382 12.39 16 684 333 10 55 2075 280 35 15 315
05/05/2016 3649 21913 16.4 19 701 287 29 90 2249 370 42 22 412
05/06/2016 3539 19023 14.79 15 575 298 8 85 2112 502 57 31 563
@ASRagab
ASRagab / nQueens.scala
Created July 29, 2018 19:07
Brute Force nQueens
object nQueens extends App {
type Solution = IndexedSeq[Int]
def createSolutions(n: Int): Seq[Solution] = {
(0 until n).permutations.toSeq
}
def verifySolution(s: Solution): Boolean = {
s.indices.combinations(2).forall(x => Math.abs(x(0) - x(1)) != Math.abs(s(x(0)) - s(x(1))))
}
@ASRagab
ASRagab / recursionSchemes.scala
Last active October 7, 2018 08:18
Sample implementation
package Other
import scalaz.Functor
import scala.language.higherKinds
object exampleList {
sealed trait mList
case object mNil extends mList
@ASRagab
ASRagab / StreamZipper.scala
Created February 18, 2019 20:05
StreamZipper with Comonad Instance
import cats._
import cats.implicits._
case class StreamZipper[A](left: Stream[A], focus: A, right: Stream[A]) {
def moveLeft: StreamZipper[A] =
if (left.isEmpty) this
else new StreamZipper[A](left.tail, left.head, focus #:: right)
def moveRight: StreamZipper[A] =
if (right.isEmpty) this
@ASRagab
ASRagab / algos.md
Last active July 14, 2024 18:35
Algos and Data Structures

Topics

Algos

  1. Baby Gin Problem
  2. Lexicographic–Order
  3. Johonson-Trotter
  4. Minimum-exchange Requirement
  5. Knapsack Problem and Fractional Knapsack Method
  6. Huffman coding
@ASRagab
ASRagab / README.md
Last active June 20, 2019 17:19
Moto TNT Presentation

Instructions

pip install boto3 moto 'moto[server]'

Usage

To start moto server for sqs (ONLY FOR NON BOTO TESTING):

@ASRagab
ASRagab / parallel
Created March 4, 2020 21:05 — forked from mjambon/parallel
bash: Run parallel commands and fail if any of them fails
#! /bin/bash
#
# Run parallel commands and fail if any of them fails.
#
set -eu
pids=()
for x in 1 2 3; do