Mix.install([{:vega_lite, "~> 0.1.6"}, {:kino_vega_lite, "~> 0.1.7"}])
alias VegaLite, as: Vl
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
from random import random | |
from math import cos, pi, radians, degrees, sin, sqrt | |
METER_PER_DEGREE = 111_139 | |
def generate_location_near(*, lat: float, lng: float, distance: float) -> tuple[float, float]: | |
lat_radian, lng_radian = radians(lat), radians(lng) | |
w, t = (distance / METER_PER_DEGREE) * sqrt(random()), 2 * pi * random() |
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
from functools import lru_cache | |
type Group = tuple[int, ...] | |
type Result = tuple[int, int] | |
type SpringConfiguration = tuple[str, Group] | |
OPERATIONAL = "." | |
DAMAGED = "#" | |
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 run_1_bin, do: input!() |> String.split("\n") |> Enum.map(fn d -> d |> String.replace("F", "0") |> String.replace("B", "1") |> String.replace("R", "1") |> String.replace("L", "0") |> String.to_integer(2) end) |> Enum.max() | |
def run_2_bin, do: input!() |> String.split("\n") |> Enum.map(fn d -> d |> String.replace("F", "0") |> String.replace("B", "1") |> String.replace("R", "1") |> String.replace("L", "0") |> String.to_integer(2) end) |> Enum.sort() |> (fn [_ | tail] = total -> total |> Enum.zip(tail) |> Enum.filter(fn {a, b} -> b - a != 1 end) |> (fn [{_, b}] -> b - 1 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
defmodule LogicChallenge do | |
@type combination :: String.t() | |
@spec run :: combination | :error | |
def run() do | |
1..999 | |
|> Enum.map(&to_string/1) | |
|> Enum.map(&String.pad_leading(&1, 3, "0")) | |
|> Enum.map(&String.graphemes/1) | |
|> Enum.filter(&check/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
select | |
(select | |
cls.relname | |
from | |
pg_class cls | |
where | |
cls.oid = cnstr.conrelid) as tbl, | |
(select | |
array_agg(attname) | |
from |
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
import datetime | |
from typing import Dict, Any | |
from hypothesis import strategies | |
from django.db import models | |
from django.db.models import F, When, Case | |
class MessageManager(models.Manager): | |
def latest_distinct(self): |
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
Duration toDuration(String duration) { | |
var tokens = duration.split(":").map(int.parse).toList(); | |
if (tokens.length == 3) | |
return Duration(hours: tokens[0], minutes: tokens[1], seconds: tokens[2]); | |
else | |
return Duration(hours: tokens[0], minutes: tokens[1]); | |
} | |
Duration timediff(String startTime, String endTime) { |
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
/// Tried to autoreloading aqueduct on code change. First attempt off my head. | |
/// Dependency: `watcher: ^0.9.7+10`, maybe this whole thing is a bad idea? | |
/// | |
/// TODO: | |
/// 1. Refactor so that it has minimal code change from the generated `bin/main.dart` | |
/// 2. Reload only once if lots of files change (i.e. scaffolding while devserver was running) | |
/// 3. Take hints from configuration file | |
/// 4. What to do if error occurs? | |
import "package:watcher/watcher.dart"; |
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
""" | |
This is from an actual snippet of mine, trimmed down, in order to answer a question asked in Python Bangladesh Group on | |
adding extra buttons in Admin list. | |
""" | |
from django.contrib import admin | |
from django.urls import reverse | |
from django.utils.html import mark_safe | |
from .models import * |
NewerOlder