Fairly straightforward, but installing postgres via brew wouldn't work until I followed the instructions in this comment: Homebrew/legacy-homebrew#35240 (comment)
| Elixir | Ruby |
|---|---|
| mix | ruby |
| hex | rubygems |
| # Run this script with: | |
| # curl -sL https://gist.github.com/JeffCohen/60e8d8e3be66d4f167b1249fb1bd451a/raw | bash -E - | |
| cd | |
| echo | |
| echo "Web Development Setup Script for Mac, Version 0.15" | |
| echo | |
| echo "This will take about 25 minutes. Do not turn off your computer until this is complete." | |
| echo "All progress is being recorded to a file named install-log.txt" |
| # This script is for Windows 10. | |
| # The Windows Subsystem for Linux must be enabled before running this script. | |
| # | |
| # Run this script from a Windows bash session with: | |
| # | |
| # curl -sL https://gist.github.com/JeffCohen/8b81c334c313340d50810a88c0df2bfb/raw | bash -E - | |
| cd | |
| echo |
| # Be sure to restart your server when you modify this file. | |
| # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces. | |
| # Rails.backtrace_cleaner.add_silencer { |line| line =~ /lib/ } | |
| # You can also remove all the silencers if you're trying to debug a problem that might stem from framework code. | |
| # Rails.backtrace_cleaner.remove_silencers! | |
| module ActionDispatch | |
| class ExceptionWrapper |
| # Python 3 | |
| # | |
| # https://docs.python.org/3/howto/urllib2.html | |
| # http://api.open-notify.org/astros.json | |
| # This code works. Run it to verify. | |
| # Then read the challenge at the bottom of this file. | |
| import urllib.request | |
| import json |
| # (Run this code with Python 3 only.) | |
| # | |
| # This program decodes a secret message by advancing each | |
| # letter by 2 places. Spaces and punctuation should remain | |
| # unchanged. | |
| # Examples: | |
| # "nwrfml" decodes into: "python" | |
| # "ynnjc" decodes into: "apple" | |
| # |
| # Example usage: | |
| # Product.sample => returns a Product | |
| # Product.sample(3) => returns an array of 3 products | |
| # Product.sample(3, true).order('title') => allows chaining | |
| class ActiveRecord::Base | |
| # Choose rows at random | |
| def self.sample(n = 1, keep_as_relation = false) | |
| rows = offset(rand(0...(count-n-1))).limit(n) |
| defmodule HelloPhoenix.MoviesController do | |
| use HelloPhoenix.Web, :controller | |
| require Logger | |
| def show(conn, %{"id" => query}) do | |
| results = fetch_by_id(query) | |
| # results is a hash that might have a key named "Error" | |
| # in which case we need to try to query by title instead of id |
Fairly straightforward, but installing postgres via brew wouldn't work until I followed the instructions in this comment: Homebrew/legacy-homebrew#35240 (comment)
| Elixir | Ruby |
|---|---|
| mix | ruby |
| hex | rubygems |
| class TreeNode: | |
| def __init__(self, content): | |
| self.content = content | |
| self.yes = None | |
| self.no = None | |
| def is_question(self): | |
| return (self.yes != None or self.no != None) | |
| # Prepare the decision tree |
| # I don't understand the output (shown below). | |
| # L is local to f, right? So how are the | |
| # contents of L remembered between invocations? | |
| def f(a, L=[]): | |
| L.append(a) | |
| return L | |
| print(f(1)) | |
| print(f(2)) |