Skip to content

Instantly share code, notes, and snippets.

@mzemel
mzemel / commands.sh
Last active April 28, 2020 23:14
Terminal commands
cd ~/jeopardy # change to application directory (run all commands in this directory)
bundle exec rails server -b 0.0.0.0 # start application (available on host machine at localhost:3000)
git pull origin master # get latest code
bundle exec rails db:migrate # apply database migrations
bundle install # install any missing dependencies
bundle exec rails assets:precompile # build .css files
bin/webpack # build .js files
bundle exec rails console # start rails console
sqlite3 db/development.sqlite3 # start SQL console
> .headers on # add headers
@mzemel
mzemel / emoji.rb
Created February 13, 2018 16:00
Text to Emoji
#!/usr/bin/env ruby
A = <<-A
+
+ +
+++
+ +
+ +
A
@mzemel
mzemel / 02_24_16.md
Last active February 25, 2016 18:30
Creating a modular component for React and Rails

Rails, React, and ActiveModelSerializers

Creating a modular component for React and Rails

Problem: We have several RESTful resources that could use just single, generic React component to display them. To populate a table dynamically, we need to give some meta-data to the React component. This will take the form of a reusable Ruby JSON-serializer.

React side

React is rendered in Rails

Feel free to skip this, as it's more background.

@mzemel
mzemel / projects_original.html.erb
Last active February 25, 2016 00:45
Original Projects
# app/views/projects/index.html.erb
<p id="notice"><%= notice %></p>
<%= react_component "ProjectList", url: "/projects", pollInterval: 5000, data: @projects.to_json %>
@mzemel
mzemel / macro_2.ex
Last active October 22, 2015 16:16
defmodule SweetSpot do
defmacro if(predicate, do: expression) do
end
end
defmodule Test do
require SweetSpot
SweetSpot.if(true, do: IO.puts "Hello world")
defmodule Calculator do
use Application
# See http://elixir-lang.org/docs/stable/elixir/Application.html
# for more information on OTP Applications
def start(_type, initial_value) do
import Supervisor.Spec, warn: false
children = [
# Define workers and child supervisors to be supervised
defmodule Calculator.Mixfile do
use Mix.Project
def project do
[app: :calculator,
version: "0.0.1",
elixir: "~> 1.0",
build_embedded: Mix.env == :prod,
start_permanent: Mix.env == :prod,
deps: deps]
defmodule Calculator do
use GenServer
###
# External API
def start_link(initial \\ 0) do
GenServer.start_link(__MODULE__, initial, name: __MODULE__)
end
@mzemel
mzemel / otp_1.ex
Last active October 22, 2015 15:38
defmodule MyServer do
use GenServer
def handle_call({:plus, number}, _from, current_number) do
new_number = current_number + new_value
{:reply, new_number, new_number}
end
end
defmodule Greeter do
def greet do
receive do
{sender, msg} ->
send sender, {:ok, "Hello #{msg}"}
greet
end
end
end