Skip to content

Instantly share code, notes, and snippets.

@mgamini
mgamini / Elixir Email Validation
Last active March 27, 2023 17:42
Elixir Email Validation
defmodule EmailValidator do
# ensure that the email looks valid
def validate_email(email) when is_binary(email) do
case Regex.run(~r/^[\w.!#$%&’*+\-\/=?\^`{|}~]+@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*$/i, email) do
nil ->
{:error, "Invalid email"}
[email] ->
try do
Regex.run(~r/(\w+)@([\w.]+)/, email) |> validate_email
@krakatoa
krakatoa / handler.lua
Created August 25, 2014 22:07
Event handling mod_lua
-- local s = event:serialize("xml")
local name = event:getHeader("Event-Name")
freeswitch.consoleLog("NOTICE", "Got event! " .. name)
if name == "DTMF" then
end
@afrantisak
afrantisak / escript_stdin.erl
Last active November 9, 2018 06:41
Escript read input file from command-line filename or from stdin if not supplied
%% -*- erlang -*-
%% usage:
%% #!/usr/bin/env escript
%% -include("escript_stdin.erl").
%% progname() -> "program_name_for_usage_text".
%% chunk(Data) -> io:format("Input file:~n~s~n", [Data]).
main([]) ->
read(standard_io);
main([Filename]) ->
{ok, IoDevice} = file:open(Filename, read),
@bcherny
bcherny / gist:de24955c15430efd99f1
Last active April 30, 2021 12:09
How to squash commits with git

Let's say you have a Pull Request from myBranch to master with 3 commits, and you want them to appear as a single commit in master.

If you're merging on the command line, this is trivial:

git checkout master
git merge --squash myBranch
git commit
@spacejam
spacejam / gist:dd5901c8b2920bb0f1ec
Last active June 19, 2018 12:59
erlang net_kernel:connect_node/1 code dive

otp/lib/kernel/src/net_kernel.erl

-spec connect_node(Node) -> boolean() | ignored when
  Node :: node().
%% explicit connects
connect_node(Node) when is_atom(Node) ->
  request({connect, normal, Node}).

otp/lib/kernel/src/net_kernel.erl

@joakin
joakin / git-find-me-the-fucking-deleted-file.sh
Last active September 27, 2025 02:49
finding a deleted file in a git repository
# If you don't remember the exact path/name, search the log for deleted files
git log --diff-filter=D --summary | grep delete
# Find the file you want to get from the ouput, and use the path
# Find the commits that involved that path
git log --all -- some/path/to/deleted.file
# Bring the file back to life to the current repo (sha commit of parent of commit that deleted)
git checkout shaofthecommitthatdeletedthefile^ -- some/path/to/deleted.file
@junegunn
junegunn / b.rb
Last active December 6, 2025 22:05
b - browse Chrome bookmarks with fzf
#!/usr/bin/env bash
# vim: set filetype=ruby:
# b - browse Chrome bookmarks with fzf
[ $(uname) = Darwin ] || exit 1
which fzf > /dev/null 2>&1 || brew reinstall --HEAD fzf || exit 1
/usr/bin/ruby -x "$0" |
fzf-tmux -u 30% --ansi --multi --no-hscroll --tiebreak=begin |
awk 'BEGIN { FS = "\t" } { print $2 }' |
@powerman
powerman / AsciidocCheatsheet.adoc
Last active December 4, 2025 18:58
Asciidoc cheatsheet for GitHub

Asciidoc cheatsheet for GitHub

@stevedomin
stevedomin / create_post.exs
Last active December 26, 2024 09:19
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
@swlaschin
swlaschin / ConstrainedTypesExamples.fsx
Last active October 10, 2025 10:40
Examples of creating constrained types in F#
// General hints on defining types with constraints or invariants
//
// Just as in C#, use a private constructor
// and expose "factory" methods that enforce the constraints
//
// In F#, only classes can have private constructors with public members.
//
// If you want to use the record and DU types, the whole type becomes
// private, which means that you also need to provide:
// * a constructor function ("create").