Skip to content

Instantly share code, notes, and snippets.

View scottdavis's full-sized avatar

Scott Davis scottdavis

View GitHub Profile
@scottdavis
scottdavis / go-stream-file-between-goroutines-with-channel.go
Created August 21, 2024 06:24 — forked from abitofhelp/go-stream-file-between-goroutines-with-channel
This gist implements a streaming process where a chunk of data is read from a file in a goroutine, the data is passed through a channel to another goroutine, which writes the data to a file.
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2018 A Bit of Help, Inc. - All Rights Reserved, Worldwide.
// Use of this source code is governed by a MIT license that can be found in the LICENSE file.
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Package main implements streaming of a file through a buffered channel where it is written to a new file.
// A data race condition arose in the for loop that reads data from the input file and sending it to the channel.
// I moved the allocation of the buffer to the top of the loop, to resolve the data race issue.
// I've created a companion gist,"go-stream-file-between-goroutines-with-pipe" that resolves the race issue using a
// FIFO pipe. It worked, but the price was that it was slower than using a channel.
UI:
- https://github.com/rivo/tview
- https://github.com/fyne-io/fyne
PacketDecoding:
- https://github.com/kgolding/go-decoder
Testing:
- https://github.com/stretchr/testify
# lib/monitor.ex
defmodule MyApp.Monitor do
def health_check do
ExStatsD.histogram(get_concache_mem_size(:css_cache), "css.cache.memory", ["css_cache_memory"])
ExStatsD.histogram(get_concache_mem_size(:sass_cache), "sass.cache.memory", ["sass_cache_memory"])
ExStatsD.histogram(ConCache.size(:css_cache), "css.cache.size", ["css_cache_size"])
ExStatsD.histogram(ConCache.size(:sass_cache), "sass.cache.size", ["sass_cache_size"])
ExStatsD.histogram(:erlang.memory(:ets), "erlang.ets.memory", ["ets_size"])
ExStatsD.histogram(:erlang.memory |> Keyword.get(:total), "erlang.memory.memory", ["ets_size"])
defmodule Monitor do
def health_check do
ExStatsD.histogram(get_concache_mem_size(:css_cache), "css.cache.memory", ["css_cache_memory"])
ExStatsD.histogram(get_concache_mem_size(:sass_cache), "sass.cache.memory", ["sass_cache_memory"])
ExStatsD.histogram(ConCache.size(:css_cache), "css.cache.size", ["css_cache_size"])
ExStatsD.histogram(ConCache.size(:sass_cache), "sass.cache.size", ["sass_cache_size"])
ExStatsD.histogram(:erlang.memory(:ets), "erlang.ets.memory", ["ets_size"])
ExStatsD.histogram(:erlang.memory |> Keyword.get(:total), "erlang.memory.memory", ["ets_size"])
end
@doc """
Converts Elixir map into a sass map
"""
def convert_to_sass(map) when is_map(map) do
"(" <> Enum.map_join(map, ",", fn {k, v} ->
"#{convert_to_sass(k)}:#{convert_to_sass(v)}"
end) <> ")"
end
@doc """
Converts Elixir atom into its corresponding sass value
@scottdavis
scottdavis / SassMeister-input-HTML.html
Created September 25, 2015 19:57
Generated by SassMeister.com.
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css">
<section class='display-pane-container'>
<div class='media' style='max-width:1200px;'>
<div class='photo'>
<img src='http://placecage.com/1200/700' class='player-photo' />
</div>
<div class='left-control'>
<span class='fa fa-arrow-circle-o-left fa-3x'></span>
</div>
<div class='right-control'>
@scottdavis
scottdavis / SassMeister-input-HTML.html
Created September 24, 2015 19:40
Generated by SassMeister.com.
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css">
<section class='display-pane-container'>
<div class='media' style='max-width:700px;max-height:1200px;'>
<div class='photo'>
<img src='http://placecage.com/700/1200' class='player-photo' />
</div>
<div class='photo ng-hide'>
<img src='http://placecage.com/1200/700' class='player-photo' />
</div>
<div class='left-control'>
@scottdavis
scottdavis / SassMeister-input-HTML.html
Last active August 29, 2015 14:26
Generated by SassMeister.com.
<div class='container'>
<div class='agent'>
<div class='profile content'>
<img src='http://www.placecage.com/200/300' />
</div>
<div class='logo content'>
<img src='http://www.placecage.com/200/125' />
</div>
<div class='name content'>
<p>Nick Cage</p>
@scottdavis
scottdavis / SassMeister-input-HTML.html
Created August 4, 2015 15:31
Generated by SassMeister.com.
<div class='container'>
<div class='agent'>
<div class='profile'>
<img src='http://www.placecage.com/200/300' />
</div>
</div>
<div class='agent'>
<div class='profile'>
<img src='http://www.placecage.com/200/300' />
</div>
@scottdavis
scottdavis / SassMeister-input.scss
Created May 1, 2015 00:54
Generated by SassMeister.com.
// ----
// libsass (v3.1.0)
// ----
// We are generating this in forceBase.scss:
$spacing-xxx-small: 0.125rem;
$spacing-xx-small: 0.25rem;
$spacing-x-small: 0.5rem;
$spacing-small: 0.75rem;
$spacing-medium: 1rem;