Skip to content

Instantly share code, notes, and snippets.

View AntonFagerberg's full-sized avatar

Anton Fagerberg AntonFagerberg

View GitHub Profile
@AntonFagerberg
AntonFagerberg / gist:3843331
Created October 6, 2012 01:08
Sucky Sudoku solver
class SudokuSolver
def initialize (m_input = Array.new(9) { [] }, m_solve = Array.new(9) { [] })
@m_input = m_input
@m_solve = m_solve
0.upto(80) do |i|
set_cell(i, 0, @m_input)
set_cell(i, 0, @m_solve)
end
end
@AntonFagerberg
AntonFagerberg / gist:6171895
Created August 7, 2013 07:17
Play concurrency test
package controllers
import play.api._
import play.api.mvc._
import scala.concurrent.{ExecutionContext, Future}
import play.api.libs.concurrent.Execution.Implicits._
import play.api.libs.ws.WS
object Application extends Controller {
object IndependentSet {
def printMatrix(matrix: List[List[Int]]): Unit = {
matrix.foreach(row => println(row.mkString(" | ")))
}
def addVertex(matrix: List[List[Int]], neighbours: List[Int]): List[List[Int]] = {
matrix
.zipWithIndex
.map {
case (row, index) => row ::: List(if (neighbours.contains(index)) 1 else 0)
import java.util.PriorityQueue;
import java.util.Random;
public class Main3 {
public class Tuple implements Comparable<Tuple> {
final int hash;
final long value;
public Tuple(long value, int hash) {
this.value = value;
get "/throw-test-1" do
throw :some_failure
end
get "/throw-test-2" do
Task.start_link(fn -> throw :some_failure end)
# Wait for task in some way
end
defp handle_errors(conn, %{kind: _kind, reason: _reason, stack: _stack} = hej) do
defmodule Hello do
defstruct yo: ""
end
defimpl Inspect, for: Hello do
import Inspect.Algebra
def inspect(_thing, _opts) do
concat ["test"]
end
@AntonFagerberg
AntonFagerberg / gist:2b0e2759d2e03f3948d9
Last active June 28, 2017 14:35
Elixir Plug form parser
defmodule Router do
use Plug.Router
plug Plug.Parsers, parsers: [:urlencoded, :json],
pass: ["text/*"],
json_decoder: Poison
plug :match
plug :dispatch
post "test" do
defmodule P5 do
def work(num, list, target, result \\ "")
def work(num, [], target, result) do
if num == target, do: IO.puts "#{result}#{num |> abs |> to_string}"
end
def work(num, [head | tail], target, result) do
work(head, tail, target - num, "#{result}#{abs(num)} + ")
work(-head, tail, target - num, "#{result}#{abs(num)} - ")
"abcdef" |> String.split("", trim: true) |> Enum.chunk(3, 1) |> Enum.map(&Enum.join/1)
import System.Directory
import Codec.Picture
import Data.Either
type RGB = (Int, Int, Int)
main :: IO ()
main =
run "blocks" 1 "/Users/anton/Downloads/fantasy_art_blizzard_entertainment_artwork_starcraft_heart_of_desktop_1920x1080_hd-wallpaper-949727.png" "test3.html"