Skip to content

Instantly share code, notes, and snippets.

defmodule CounterWeb.Counter do
use Phoenix.LiveView
def render(assigns) do
~L"""
<div>
<h1>The count is: <%= @val %></h1>
<button phx-click="dec">-</button>
<button phx-click="inc">+</button>
</div>
@brianstorti
brianstorti / timing
Created March 14, 2018 18:09
timing - script to prefix stdout with the executing time
#!/usr/bin/env bash
# Usage:
# $ command | timing
#
# Example:
# $ rails server | timing
# 00:00:00 | rails server -b 0.0.0.0
# 00:00:04 | => Booting Puma
# 00:00:04 | => Rails 5.1.3 application starting in development on http://0.0.0.0:3000
begin
require 'bundler/inline'
rescue LoadError => e
$stderr.puts 'Bundler version 1.10 or later is required. Please update your Bundler'
raise e
end
gemfile(true) do
source 'https://rubygems.org'
# Activate the gem you are reporting the issue against.
@brianstorti
brianstorti / gist:4f0c4ff0b5cfc092aa7f5a5f187b6f8b
Created April 7, 2016 19:34
rabbitmq_delayed_message_exchange.log
=ERROR REPORT==== 7-Apr-2016::21:31:31 ===
Error on AMQP connection <0.3317.0> (127.0.0.1:49193 -> 127.0.0.1:5672, vhost: '/', user: 'guest', state: running), channel 1:
{{{undef,
[{time_compat,erlang_system_time,[milli_seconds],[]},
{rabbit_delayed_message,internal_delay_message,4,
[{file,"src/rabbit_delayed_message.erl"},{line,179}]},
{rabbit_delayed_message,handle_call,3,
[{file,"src/rabbit_delayed_message.erl"},{line,118}]},
{gen_server,try_handle_call,4,[{file,"gen_server.erl"},{line,607}]},
{gen_server,handle_msg,5,[{file,"gen_server.erl"},{line,639}]},
{
"query" => "\"\\n query IntrospectionQuery {\\n __schema {\\n queryType { name }\\n mutationType { name }\\n types {\\n ...FullType\\n }\\n directives {\\n name\\n description\\n args {\\n ...InputValue\\n }\\n onOperation\\n onFragment\\n onField\\n }\\n }\\n }\\n\\n fragment FullType on __Type {\\n kind\\n name\\n description\\n fields(includeDeprecated: true) {\\n name\\n description\\n args {\\n ...InputValue\\n }\\n type {\\n ...TypeRef\\n }\\n isDeprecated\\n deprecationReason\\n }\\n inputFields {\\n ...InputValue\\n }\\n interfaces {\\n ...TypeRef\\n }\\n enumValues(includeDeprecated: true) {\\n name\\n description\\n isDeprecated\\n deprecationReason\\n }\\n possibleTypes {\\n ...TypeRef\\n }\\n }\\n\\n fragment InputValue on __InputValue {\\n name\\n de
Java Virtual Machine statistics monitoring tool (jstat -options for all the options)
$ jstat -gcutil process_id 1000
S0 -> Survivors 0
S1 -> Survivors 1
E -> Eden
O -> Old
P -> Perm
YGC -> Young GC
@brianstorti
brianstorti / priority_queue.rb
Last active November 17, 2022 16:14
Priority queue implementation in Ruby
class PriorityQueue
attr_reader :elements
def initialize
@elements = [nil]
end
def <<(element)
@elements << element
bubble_up(@elements.size - 1)
Generated with:
rvm-restart
rvm get head
echo 1.26.4 >| $rvm_path/VERSION
rvm-restart
(
export PS4="+ %* %F{red}%x:%I %F{green}%N:%i%F{white} %_"
set -o xtrace
rvm --trace install 2.2.0 2>&1 | tee big.log
@brianstorti
brianstorti / gist:8a2b96c65457905829bb
Last active August 29, 2015 14:12
rvm install error
Found old RVM 1.26.4 - updating.
Downloading https://get.rvm.io
No GPG software exists to validate rvm-installer, skipping.
Downloading https://github.com/wayneeseguin/rvm/archive/master.tar.gz
Upgrading the RVM installation in /Users/brianstorti/.rvm/
RVM PATH line found in /Users/brianstorti/.bashrc /Users/brianstorti/.zshrc.
RVM sourcing line found in /Users/brianstorti/.bash_profile /Users/brianstorti/.zlogin.
Upgrade of RVM in /Users/brianstorti/.rvm/ is complete.
@brianstorti
brianstorti / client.rb
Created December 10, 2014 07:06
dumb client/server socket
require 'socket'
class Client
private
attr_reader :host, :port
public
def initialize(host, port)
@host, @port = host, port
end