Skip to content

Instantly share code, notes, and snippets.

name: Elixir CI
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
env:
MIX_ENV: test
defmodule Parser do
@moduledoc """
Sample parser for article on:
http://stefan.lapers.be/posts/elixir-writing-an-expression-parser-with-nimble-parsec/
"""
import NimbleParsec
not_ = string("!") |> label("!")
and_ = string("&&") |> replace(:&&) |> label("&&")
or_ = string("||") |> replace(:||) |> label("||")
@slashdotdash
slashdotdash / upsert_profile.ex
Last active July 26, 2020 23:09
Upserts in Ecto using `Ecto.Multi`
defp upsert_profile(multi, source, source_uuid, profile_url) do
profile = %Profile{
source: source,
source_uuid: source_uuid,
profile: profile_url,
}
Ecto.Multi.insert(multi, source_uuid, profile, on_conflict: [set: [profile: profile_url]], conflict_target: [:source, :source_uuid])
end
@nerdyworm
nerdyworm / rename.sh
Created July 30, 2016 17:40
rename a phoenix project
#!/bin/bash
set -e
CURRENT_NAME="CurentName"
CURRENT_OTP="current_name"
NEW_NAME="NewName"
NEW_OTP="new_name"
@theoretick
theoretick / ruby_tap_in_elixir.ex
Last active January 23, 2020 05:56
ruby #tap in elixir
iex(1)> defmodule Util do
...(1)> def tap(input, func) do
...(1)> func.(input)
...(1)> input
...(1)> end
...(1)> end
{:module, Util,
<<70, 79, 82, 49, 0, 0, 4, 212, 66, 69, 65, 77, 69, 120, 68, 99, 0, 0, 0, 164, 131, 104, 2, 100, 0, 14, 101, 108, 105, 120, 105, 114, 95, 100, 111, 99, 115, 95, 118, 49, 108, 0, 0, 0, 4, 104, 2, ...>>,
{:tap, 2}}
iex(2)> import Util
<?php
namespace Roots\Sage\Nav;
use Roots\Sage\Utils;
/**
* Cleaner walker for wp_nav_menu()
*
* Walker_Nav_Menu (WordPress default) example output:
@mrdziuban
mrdziuban / PsySH_with_Yii.md
Last active August 21, 2019 10:20
How to use PsySH with a Yii application

Using PsySH (GitHub) as the Yii shell

  • Issue the following commands from the command line in your Yii application directory:
    • chmod +x shell
    • mkdir extensions/yiishell
    • wget -O extensions/yiishell/psysh psysh.org/psysh
    • chmod +x extensions/yiishell/psysh
  • Copy the file init.php below to extensions/yiishell/init.php and update any paths to work with your application configuration
  • Copy the file config.php below to extensions/yiishell/config.php. Change or add to the config array with the options you'd like to use (available options)
  • Now you can start PsySH with the command extensions/yiishell/psysh extensions/yiishell/init.php --config extensions/yiishell/config.php
@jbowens
jbowens / ListCodeDefinition.php
Last active April 9, 2021 09:06
A [list] BBCode definition for jBBCode using [*] for list items.
<?php
require_once "jBBCode" . DIRECTORY_SEPARATOR . "Parser.php";
/**
* Implements a [list] code definition that provides the following syntax:
*
* [list]
* [*] first item
* [*] second item
@haf
haf / gist:2843680
Created May 31, 2012 14:19
Get SSH working on Vagrant/Windows/Git

If you are using vagrant, you probably-statistically are using git. Make sure you have its binary folder on your path, because that path contains 'ssh.exe'.

Now, modify C:\vagrant\vagrant\embedded\lib\ruby\gems\1.9.1\gems\vagrant-1.0.3\lib\vagrant\ssh.rb to comment out the faulty Windows check and add a real SSH check:

# if Util::Platform.windows?
  # raise Errors::SSHUnavailableWindows, :host => ssh_info[:host],
                                       # :port => ssh_info[:port],
                                       # :username => ssh_info[:username],
 # :key_path =&gt; ssh_info[:private_key_path]
@jlong
jlong / uri.js
Created April 20, 2012 13:29
URI Parsing with Javascript
var parser = document.createElement('a');
parser.href = "http://example.com:3000/pathname/?search=test#hash";
parser.protocol; // => "http:"
parser.hostname; // => "example.com"
parser.port; // => "3000"
parser.pathname; // => "/pathname/"
parser.search; // => "?search=test"
parser.hash; // => "#hash"
parser.host; // => "example.com:3000"