| 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 |
| 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) |
| 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
| 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 |
| # 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.
| -- ============================================================================= | |
| -- A single-file Neovim configuration inspired by AstroNvim's UX conventions | |
| -- with a minimal, readable setup. | |
| -- ============================================================================= | |
| -- | |
| -- REQUIREMENTS: | |
| -- Neovim >= 0.11 (uses vim.lsp.config/enable API and LspProgress event) | |
| -- git (lazy.nvim bootstrap and gitsigns) | |
| -- make (telescope-fzf-native build step) | |
| -- A Nerd Font (icons in neo-tree, lualine, bufferline, dashboard) |
My best friend is a musician, I’m a coder. Professionally and also as our favorite hobbies. He uses instruments to create songs, I use languages to create apps. We often fall into parallels between both worlds, but yesterday’s conversation went somewhere new.
He told me he bought a trumpet. No previous experience, never touched one before. I asked if he was going to take classes or figure it out himself. He laughed… already figuring it out himself, obviously. So he walked me through it.
First he figured out the mechanics. How much the sound changes when he presses the first valve, the second, the third. He knows a little trombone, so he could pick up the different mouth positions, each one produces a different note in a different range.