Skip to content

Instantly share code, notes, and snippets.

@xdcrafts
xdcrafts / Slae.GaussSeidel.hs
Created September 27, 2012 06:25
Implementation of Gauss-Seidel method for solving of system of linear algebraic equations.
-- file Slae.GaussSeidel xdCrafts 27.09.2012
module
Slae.GaussSeidel (
solveWithAccuracy,
solveWithAccuracy1
)
where
-- http://en.wikipedia.org/wiki/Gauss%E2%80%93Seidel_method
-- function that represents Xi(k+1)
@xdcrafts
xdcrafts / Quasar.Main.hs
Created October 3, 2012 02:46
Simple http web server implementation.
module Quasar.Main where
import Control.Monad
import Data.Char
import System.IO
import Network
import Data.Time.LocalTime
data RequestType = GET | POST deriving (Show)
@xdcrafts
xdcrafts / Integration.Simpson.hs
Created November 6, 2012 10:04
Implementation of Simpson method of numerical integration.
-- file Integration.Simpson.hs xdCrafts 06.11.2012
module
Integration.Simpson (
integrate,
integrateFromN,
integrateWithAccuracy
)
where
-- function that splits tuple by odd and even components
@xdcrafts
xdcrafts / gist:4084892
Created November 16, 2012 06:50
Utility that copies all files from source directory that absent in target directory.
module Main (main) where
import System.Environment (getArgs)
import System.Directory (getDirectoryContents, doesFileExist, copyFile)
import Control.Monad (filterM, mapM)
import Data.List
-- Line separator
lineSeparator = "\n"
@xdcrafts
xdcrafts / SimpleWarpExample.hs
Created August 8, 2013 06:15
Simple example of Warp WAI usage.
{-# LANGUAGE OverloadedStrings #-}
module Main where
import Data.ByteString.Lazy.Char8 hiding (putStrLn)
import Network.HTTP.Types.Status
import Network.Wai
import Network.Wai.Handler.Warp (run)
import System.IO
import System.Exit
import Control.Concurrent
package net.thumtack.flower.spring;
import net.thumbtack.flower.AsFunction;
import net.thumbtack.flower.Namespaced;
import net.thumbtack.flower.Action;
import net.thumbtack.flower.Middleware;
import net.thumbtack.flower.utils.MapApi;
import net.thumbtack.flower.impl.DefaultAction;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import net.thumbtack.flower.spring.example.Authenticator
import net.thumbtack.flower.spring.example.LoggingMiddleware
import net.thumbtack.flower.spring.example.Receiver
import net.thumbtack.flower.spring.example.User
import net.thumbtack.flower.spring.example.email.EmailAuthorizer
import net.thumbtack.flower.spring.example.email.EmailRequestValidator
import net.thumbtack.flower.spring.example.email.EmailSender
import net.thumbtack.flower.spring.example.sms.SmsAuthorizer
import net.thumbtack.flower.spring.example.sms.SmsRequestValidator
import net.thumbtack.flower.spring.example.sms.SmsSender
import scala.concurrent.{Await, ExecutionContext, Future}
import scala.concurrent.duration.Duration
import scala.util.{Failure, Success, Try}
object app extends App {
import effect.Effect
import context._
import scala.concurrent.duration._
import scala.concurrent.ExecutionContext.Implicits.global
@xdcrafts
xdcrafts / ctx-scala-2.scala
Last active April 27, 2021 13:55
Scala Typesafe Context
final case class Ctx[T <: Ctx.Key[_]] private (private val map: Map[Ctx.Key[_], Any])
object Ctx {
trait Key[T] { type Value = T; override def toString: String = getClass.getTypeName.replace("$", "") }
implicit final class CtxExtension[Self <: Ctx[_]](private val self: Self) extends AnyVal {
def put[K <: Key[_]](key: K)(value: key.Value): Self with Ctx[K] =
Ctx(self.map + (key -> value)).asInstanceOf[Self with Ctx[K]]
def get[K <: Key[_]](key: K)(implicit ev: Self <:< Ctx[K]): key.Value = self.map.get(key) match {
use ggez::graphics::{self, Color, DrawMode, DrawParam, FillOptions, Mesh, Rect};
use ggez::{Context, ContextBuilder, GameError, GameResult};
use ggez::mint;
use ggez::event::{self, EventHandler};
use ggez::input::keyboard::{self, KeyCode};
use rand::prelude::*;
use std::ops::Neg;