This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule MyAppWeb.HealthController do | |
use MyAppWeb, :controller | |
alias MyAppWeb.Heartbeat | |
def root(conn, _) do | |
send_resp(conn, :no_content, "") | |
end | |
def show(conn, _) do |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def normalize(import_statement, file_path) | |
import_from = import_statement.scan(/(?<=from ').*(?=')/)[0] | |
from_path = file_path.split('/').reverse | |
to_path = import_from.split('/') | |
new_path = [] | |
while !to_path.empty? | |
case to_path.last | |
when '.' | |
new_path << to_path.pop | |
when '..' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Frame { | |
var one: Int | |
var two: Int? | |
var extras: [Int] | |
init(one: Int, two: Int?) { | |
self.one = one | |
self.two = two | |
self.extras = [Int]() | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(def y | |
(fn [improver] | |
((fn [gen] (improver (fn [v] ((gen gen) v)))) | |
(fn [gen] (improver (fn [v] ((gen gen) v))))))) | |
(def fact-improver | |
(fn [partial] | |
(fn [n] | |
(if (= n 0) | |
1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Var < Struct.new(:name, :domain) | |
def self.gen(domains) | |
domain = domains.first.product(*domains[1..-1]) | |
Var.new("__gen__#{domain.object_id}", domain) | |
end | |
def empty? | |
domain.empty? | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Memoize | |
module DefMemo | |
def defmemo(name, &block) | |
define_method(name) do |*args| | |
__memo__[name].fetch(args) do |key| | |
__memo__[name][key] = instance_exec(*args, &block) | |
end | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def call_maybe(x) | |
if block_given? | |
yield x | |
else | |
x | |
end | |
end | |
call_maybe(2) { |x| x + 1 } | |
call_maybe(2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Result | |
def self.status(status, result) | |
new(status, result) | |
end | |
def initialize(status, result) | |
@status = status | |
@result = result | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
./test.rb 2>errors.log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns if-not-empty-let.core | |
(:require [clojure.test :refer [deftest is run-tests]])) | |
(defmacro if-not-empty-let | |
([binding then] `(if-not-empty-let ~binding ~then nil)) | |
([binding then else] | |
(let [form (first binding) | |
sequence (binding 1)] | |
`(let [temp# ~sequence] | |
(if (not (empty? temp#)) |
NewerOlder