Skip to content

Instantly share code, notes, and snippets.

View bluzky's full-sized avatar
🎯
Focusing

Dung Nguyen bluzky

🎯
Focusing
View GitHub Profile
@bluzky
bluzky / request_helper.ex
Last active July 21, 2023 05:01
Elixir download/stream large file with hackney
defmodule RequestHelper do
@moduledoc """
Reference from https://gist.github.com/avdi/7990684
Stream download large file from url
"""
require Logger
@doc """
Get stream data from url
mode could be `:binary` or `:line`
@bluzky
bluzky / datetime_parser.ex
Created December 11, 2021 16:19
Elixir datetime parser with regex
defmodule DateTimeParser do
@mapping %{
"H" => "(?<hour>\\d{2})",
"I" => "(?<hour12>\\d{2})",
"M" => "(?<minute>\\d{2})",
"S" => "(?<second>\\d{2})",
"d" => "(?<day>\\d{2})",
"m" => "(?<month>\\d{2})",
"y" => "(?<year2>\\d{2})",
"Y" => "(?<year>-?\\d{4})",
@coolaj86
coolaj86 / Create a Bootable MacOS Recovery USB with Linux.md
Last active April 27, 2024 21:17
How to create Apple's Bootable MacOS Rescue Image from Linux

See bootableinstaller.com

How to create a Bootable MacOS Recovery USB from Linux

If your Mac is out-of-order or you otherwise cannot download macOS from the App Store, you can still create a bootable OS X recovery USB, and you can use that to create an Installer USB.

The downloads used in this process are legal and freely avaliable - including disk images directly from Apple's IT support pages, and open source utilities for extracting and converting pkg, dmg, and HFS+.

Mục đích bài viết này để

  1. Giới thiệu về phương pháp lập trình bất đồng bộ với cách tiếp cận khác những ngôn ngữ như Java hoặc C#.
  2. Những bước đầu tiên để viết 1 chương trình chạy bất đồng bộ bằng Elixir
  3. Hi vọng sẽ lôi kéo được thêm người học Elixir :)

1. Concurrent Programming

Concurrent Programming hiểu đơn giản là việc lập trình cho phần mềm có thể chia nhỏ tác vụ và chạy đồng thời, độc lập với nhau. Elixir là ngôn ngữ lập trình được

@bluzky
bluzky / slug.js
Last active April 8, 2024 05:01
Remove vietnamese accent javascript / Bỏ dấu tiếng Việt
function stringToSlug(str) {
// remove accents
var from = "àáãảạăằắẳẵặâầấẩẫậèéẻẽẹêềếểễệđùúủũụưừứửữựòóỏõọôồốổỗộơờớởỡợìíỉĩịäëïîöüûñçýỳỹỵỷ",
to = "aaaaaaaaaaaaaaaaaeeeeeeeeeeeduuuuuuuuuuuoooooooooooooooooiiiiiaeiiouuncyyyyy";
for (var i=0, l=from.length ; i < l ; i++) {
str = str.replace(RegExp(from[i], "gi"), to[i]);
}
str = str.toLowerCase()
.trim()
@giannisp
giannisp / gist:ebaca117ac9e44231421f04e7796d5ca
Last active March 1, 2024 14:39
Upgrade PostgreSQL 9.6.5 to 10.0 using Homebrew (macOS)
After automatically updating Postgres to 10.0 via Homebrew, the pg_ctl start command didn't work.
The error was "The data directory was initialized by PostgreSQL version 9.6, which is not compatible with this version 10.0."
Database files have to be updated before starting the server, here are the steps that had to be followed:
# need to have both 9.6.x and latest 10.0 installed, and keep 10.0 as default
brew unlink postgresql
brew install postgresql@9.6
brew unlink postgresql@9.6
brew link postgresql
@stevedomin
stevedomin / create_post.exs
Last active July 12, 2023 01:32
Using UUIDs as primary key with Ecto
defmodule MyBlog.Repo.Migrations.CreatePost do
use Ecto.Migration
def change do
create table(:posts, primary_key: false) do
add :id, :uuid, primary_key: true
add :body, :string
add :word_count, :integer
timestamps
@avdi
avdi / gist:7990684
Created December 16, 2013 17:20
Streaming a URL to a file in Elixir
def download_video(Episode[filename: filename] = episode) do
Stream.resource(fn -> begin_download(episode) end,
&continue_download/1,
&finish_download/1)
|> File.stream_to!(filename)
|> Stream.run
end
def begin_download(Episode[video_url: video_url,
account: Account[login: login,