Skip to content

Instantly share code, notes, and snippets.

@jeffweiss
jeffweiss / emit_log.exs
Last active June 29, 2022 21:02
RabbitMQ Tutorial - Elixir examples
{:ok, connection} = AMQP.Connection.open
{:ok, channel} = AMQP.Channel.open(connection)
message = Enum.join(System.argv, " ") || "Hello World!"
AMQP.Exchange.declare(channel, "logs", :fanout)
AMQP.Basic.publish(channel, "logs", "", message)
IO.puts " [x] Sent '#{message}'"
@jeffweiss
jeffweiss / eldap.exs
Created November 9, 2015 19:30
sample of using eldap from elixir
:application.ensure_all_started(:ssl)
{:ok, handle} = :eldap.open(['ldap.example.com'], [{:port, 636}, {:ssl, true}])
authenticated =
:ok == :eldap.simple_bind(handle,
'uid=jeff,ou=users,dc=example,dc=com',
'notmyrealpassword')
{:ok, {:eldap_search_result, list_of_entries, _}} =
@jeffweiss
jeffweiss / mix.exs
Last active December 18, 2018 23:13
Retrieving application version number in mix.exs from git describe
defmodule MyApp.Mixfile do
use Mix.Project
def project do
[app: :my_app,
version: get_version,
elixir: "~> 1.0",
elixirc_paths: elixirc_paths(Mix.env),
compilers: Mix.compilers,
build_embedded: Mix.env == :prod,
@jeffweiss
jeffweiss / post_message.lua
Created October 4, 2015 02:26
Sending POSTs to Elixir Phoenix using wrk or wrk2
wrk.method = "POST"
-- this assumes that we're sending to a html form endpoint with csrf protection disabled
-- wrk.body and wrk.headers would be different if we were sending a JSON payload to a JSON API endpoing
wrk.body = "message[body]=wat"
wrk.headers["Content-Type"] = "application/x-www-form-urlencoded"
@jeffweiss
jeffweiss / cleanCheckout.groovy
Created February 7, 2017 19:28
Jenkins clean checkout
#!groovy
def call() {
checkout([
$class: 'GitSCM',
branches: scm.branches,
extensions: scm.extensions + [[$class: 'WipeWorkspace'], [$class: 'LocalBranch']],
userRemoteConfigs: scm.userRemoteConfigs
])
}
@jeffweiss
jeffweiss / fpm snippet
Created April 15, 2016 17:57
snippets for elixir continuous delivery pipeline
cmd = [
'fpm',
'-t deb',
'-s dir',
'-d postgresql',
'-m ' + config[:maintainer],
"-n '#{config[:product]}'",
"--prefix /opt/puppet/#{config[:product]}",
'-v ' + deb_version,
"--deb-init #{config[:product]}.init",
@jeffweiss
jeffweiss / channels.conf
Created February 23, 2016 17:34
ohaibot channels.conf example
[<<"#ohaibot-testing">>].
[<<"#elixirconf">>].
@jeffweiss
jeffweiss / curl.sh
Created January 18, 2014 06:06
Proof that I'm not the @MaxMartinPDX troll
curl --get 'https://api.twitter.com/1.1/users/show.json' --data 'screen_name=MaxMartinPDX'
@jeffweiss
jeffweiss / gist:6057646
Last active December 20, 2015 02:39
Recently updated gems that don't specify a license
require 'gems'
require 'pp'
pp Gems.latest.map {|g| g["name"]}.
sort.
map {|n| {n => Gems.versions(n) } }.
reject {|elem| elem.has_value? "This rubygem could not be found."}.
map {|elem| {elem.keys.first => elem.values.first.all? {|h| h["licenses"].empty?}}}.
reject {|h| h.has_value? false}
@jeffweiss
jeffweiss / fetchgems.rb
Last active December 16, 2015 16:29
If bundler had a `fetch` command
require 'bundler'
require 'rubygems'
require 'rubygems/gem_runner'
require 'fileutils'
without = [:development, :test]
runner = Gem::GemRunner.new
definition = Bundler::Definition.build('Gemfile', 'Gemfile.lock', nil)
resolver = definition.resolve