This file contains hidden or 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 Weather::Interpolation | |
def initialize(x, y, z, xi, yi) | |
@x, @y, @z, @xi, @yi = x, y, z, xi, yi | |
end | |
def calc | |
# if any location closer than 10km, return this location | |
close_location = distances.index {|d| d < 10} | |
close_location ? @z[close_location] : interpolation | |
end |
This file contains hidden or 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 MigrateRedis do | |
require Logger | |
@from [host: "127.0.0.1", port: 6379] | |
@to [host: "127.0.0.1", port: 6379] | |
def migrate(from \\ @from, to \\ @to) do | |
{:ok, from} = Redix.start_link(from) | |
{:ok, to} = Redix.start_link(to) |
This file contains hidden or 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 Downloader do | |
@moduledoc""" | |
Download streams of bytes from URLs. | |
Useful to transfer large files with low RAM usage. | |
## Example with `ExAWS.S3.upload/3` | |
```elixir | |
url | |
|> Downloader.stream_body!() |
A company is planning a way to reward customers for inviting their friends.
They're planning a reward system that will give a customer points for each confirmed invitation they played a part into.
The definition of a confirmed invitation is one where another invitation's invitee invited someone.
The inviter gets (1/2)^k points for each confirmed invitation, where k is the level of the invitation:
- level 0 (people directly invited) yields 1 point
- level 1 (people invited by someone invited by the original customer) gives 1/2 points
- level 2 invitations (people invited by someone on level 1) awards 1/4 points and so on
This file contains hidden or 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
MIT License | |
Permission is hereby granted, free of charge, to any person obtaining a copy | |
of this software and associated documentation files (the "Software"), to deal | |
in the Software without restriction, including without limitation the rights | |
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
copies of the Software, and to permit persons to whom the Software is | |
furnished to do so, subject to the following conditions: | |
The above copyright notice and this permission notice shall be included in all |
This file contains hidden or 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
# List Comprehensions | |
squares = [x**2 for x in range(10)] | |
even_squares = [x**2 for x in range(10) if x % 2 == 0] | |
# Dictionary Comprehensions | |
squared_dict = {x: x**2 for x in range(10)} | |
# Lambda Functions | |
add = lambda a, b: a + b |
Deadlock detected,
The system is infected.
Zombie processes
Haunt orphaned guests.
Abort transactions,
While we break the loop.
Don’t crash the node,
It’s a dependency soup.
OlderNewer