Skip to content

Instantly share code, notes, and snippets.

View kellyfelkins's full-sized avatar

Kelly Felkins kellyfelkins

  • Pepsico
  • Brookings OR
View GitHub Profile
@kellyfelkins
kellyfelkins / gist:41f4de65b47d4d10636280d2f0cf91c3
Created December 11, 2023 19:05
crazy shell 1 liner - find module names in files ending in "chart" and grep all files to see of those are aliases or imported
# crazy shell command
find lib/dpi_web/live -name '*_chart.ex' | xargs ghead -q -n 1 | cut -d " " -f 2 | xargs -I % echo "echo '>>> %'; grep -R -E '(import|alias) %' lib/dpi_web/live;" | sh
# let's break it down
find lib/dpi_web/live -name '*_chart.ex'
# search for files like '*_chart.ex' starting in the lib/dpi_web/live directory
| xargs ghead -q -n 1
# take the first line of those file, and don't tell me the name of the file
date -j -v -90d
@kellyfelkins
kellyfelkins / keybindings.json
Created November 29, 2022 18:11
useful vscode key bindings
// Place your key bindings in this file to override the defaultsauto[]
[
{
"key": "ctrl+alt+cmd+r",
"command": "exunit.runPrevious"
},
{
"key": "ctrl+alt+cmd+a",
"command": "exunit.runAll"
},
@kellyfelkins
kellyfelkins / elixir.json
Created November 29, 2022 18:08
useful snippets in vscode
{
"Print File Line": {
"prefix": "pfl",
"body": [
"IO.puts \"#{__ENV__.file}:#{__ENV__.line}\""
]
},
"Inspect Value": {
"prefix": "iiv",
"body": [
@kellyfelkins
kellyfelkins / mumble_component.ex
Created November 22, 2022 22:13
`apply_action` if you want errors on your elixir form with embeds
def handle_event("name-change", params, socket) do
# 1. fetch the previously assigned changeset
export_changeset = socket.assigns.export_changeset
# 2. apply the changes
export_changeset = Export.changeset(export_changeset, params["export"])
# 3. the parent changeset is invalid, and there are errors in the child (embedded) changesets,
# but the parent changeset does not have errors
# 4. `apply_action` sets the action, and possibly other changes on the changeset
case Ecto.Changeset.apply_action(export_changeset, :insert) do
{:ok, data} ->
@kellyfelkins
kellyfelkins / intellij_elixir_file_watcher_settings.md
Last active April 7, 2021 00:02
intellij file watcher settings for elixir

How to configure intellij file watchers to run the elixir formatter.

@kellyfelkins
kellyfelkins / jq_examples.bash
Last active November 28, 2023 23:15
Some jq examples to remember
# These jq scripts were developed to deal with geojson files generated with https://rubygems.org/gems/advance
# This adds the filename to the path data and pipes it to less for viewing:
jq '. + {source_data: { features: [.source_data.features[] + {file: input_filename}]}}' some_geojson.json | less
# This pipes it to a new file:
jq '. + {source_data: { features: [.source_data.features[] + {file: input_filename}]}}' some_geojson.json > new_file.json
# To extract just the features while adding the filename:
jq '{features: [.source_data.features[] + {file: input_filename}]}' some_geojson.json > features.json
@kellyfelkins
kellyfelkins / challenge.ex
Last active June 3, 2019 04:48
find first singleton in list
def first_singleton(list) do
list
|> Enum.sort()
|> no_partner?()
end
def no_partner?([value | remaining_values]) do
if value == hd(remaining_values) do
Enum.reject(remaining_values, &(&1 == value))
|> no_partner?()
@kellyfelkins
kellyfelkins / edit_dot.rb
Created March 6, 2017 17:09
Simple example of unix style filter written in ruby. This one filters a dot file created by the rails-erd gem in order to put specializations in subgraphs.
#!/usr/bin/env ruby
BEGIN {
clusters = Hash.new {|h, k| h[k] = []}
}
ARGF.each_line do |line|
case line
when /\s*(\w+) -> .+?grey60/
@kellyfelkins
kellyfelkins / index.html
Created March 24, 2014 14:56
A simple d3js geo example displaying 3 points in San Francisco.
<!DOCTYPE html>
<meta charset="utf-8">
<svg class="chart"></svg>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script>
var width = 500,
height = 500,
scale = 100000,
longitude = -122.4167,