Skip to content

Instantly share code, notes, and snippets.

Avatar
🤔
scheming

Jacek Królikowski nietaki

🤔
scheming
View GitHub Profile
View gist:71d08e376539bd6df813def4c7ad7553
$ lspci -nn
00:00.0 Host bridge [0600]: Intel Corporation Xeon E3-1200 v5/E3-1500 v5/6th Gen Core Processor Host Bridge/DRAM Registers [8086:191f] (rev 07)
00:01.0 PCI bridge [0604]: Intel Corporation Xeon E3-1200 v5/E3-1500 v5/6th Gen Core Processor PCIe Controller (x16) [8086:1901] (rev 07)
00:14.0 USB controller [0c03]: Intel Corporation 100 Series/C230 Series Chipset Family USB 3.0 xHCI Controller [8086:a12f] (rev 31)
00:16.0 Communication controller [0780]: Intel Corporation 100 Series/C230 Series Chipset Family MEI Controller #1 [8086:a13a] (rev 31)
00:17.0 SATA controller [0106]: Intel Corporation Q170/Q150/B150/H170/H110/Z170/CM236 Chipset SATA Controller [AHCI Mode] [8086:a102] (rev 31)
00:1b.0 PCI bridge [0604]: Intel Corporation 100 Series/C230 Series Chipset Family PCI Express Root Port #17 [8086:a167] (rev f1)
00:1b.2 PCI bridge [0604]: Intel Corporation 100 Series/C230 Series Chipset Family PCI Express Root Port #19 [8086:a169] (rev f1)
00:1c.0 PCI bridge [0604]: Intel Corporation 100 Series/C23
View trim_samples.sh
#!/usr/bin/env bash
if [[ $# -eq 0 ]] ; then
echo 'missing directory'
exit 1
fi
dir="$1"
for filename in $dir/*.wav; do
View medium_preload_functions.ex
def category_preloader(category_names) when is_list(category_names) do
# category_names are already deduplicated
Enum.map(category_names, &RemoteService.retrieve_category_info/1)
end
query =
from(p in Post,
where: p.id in ^post_ids,
preload: [category: ^&category_preloader/1]
)
View medium_post_schema_final.ex
defmodule BlogExample.Schema.Category do
use Ecto.Schema
@primary_key {:name, :string, []}
embedded_schema do
field(:current_popularity, :integer)
end
end
View medium_virtual_field_enum_map.ex
query =
from(p in PostWithVirtualCategory,
where: p.id in ^post_ids
)
posts =
query
|> Repo.all()
|> Enum.map(&PostWithVirtualCategory.populate_category/1)
View medium_virtual_example.ex
defmodule BlogExample.Schema.PostWithVirtualCategory do
use Ecto.Schema
schema "posts" do
field(:title, :string, null: false)
field(:contents, :string, null: false)
field(:category_name, :string)
field(:category, :map, virtual: true)
View medium_preload_on_structs.ex
simpler_query = from(c in Comment, where: c.user_id == ^charlie_id)
non_preloaded = Repo.all(simpler_query)
assert Enum.all?(non_preloaded, fn c -> c.post == nil end)
comments_by_charlie = Repo.preload(non_preloaded, [:post])
refute Enum.any?(comments_by_charlie, fn c -> c.post == nil end)
View medium_simple_preload.ex
# aliases and imports omitted
query =
from(c in Comment,
where: c.user_id == ^charlie_id,
preload: [:post]
)
comments_by_charlie = Repo.all(query)
refute Enum.any?(comments_by_charlie, fn c -> c.post == nil end)
View medium_simple_query.ex
alias BlogExample.Schema.Comment
import Ecto.Query, only: [from: 2]
query =
from(c in Comment,
where: c.user_id == ^charlie_id
)
comments_by_charlie = Repo.all(query)
View medium_schemas.ex
defmodule BlogExample.Schema.User do
use Ecto.Schema
schema "users" do
field(:username, :string, null: false)
field(:full_name, :string)
has_many(:posts, BlogExample.Schema.Post)
has_many(:comments, BlogExample.Schema.Comment)
end