Skip to content

Instantly share code, notes, and snippets.

# return the unique elements of this array:
# a = []
# 10000000.times{a.push(rand(100))}
# no array.uniq please
# extra credit -- in one function, count all the occurrences of each element of a
a = []
10000000.times{a.push(rand(100))}
# Take this array:
a = [[1, 2], [3, 4], [5, 6], [7, 8], [9, 10]]
# and transform it into this array
# [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 0, 0]]
flat = a.flatten
@kangkyu
kangkyu / transpose_mock.rb
Last active August 29, 2015 14:26
Thanks to Charlie, this is great for us to have 15-minute code kata every weekday .
# write a method called "transpose" that takes this array of arrays:
# [
# ['first', 'second'],
# ['third', 'fourth']
# ]
# and transposes it into this array of arrays
# [
@kangkyu
kangkyu / gist:ea1d3606ea6e82c1fba0
Last active August 29, 2015 14:26
elm package install
elm package install
elm package install evancz/elm-html
<add & edit Bingo.elm>
# elm make --warn Bingo.elm --output index.html
elm reactor # and then open Bingo.elm file
module Bingo where
@kangkyu
kangkyu / guard_exercism.md
Last active November 2, 2018 06:19
There should be better ways - hope anybody comment it

Use guard-shell gem.

# terminal (at exercism/ruby/)
gem install guard guard-shell
guard init shell
# Guardfile

##Quiz: Lesson 3 Solutions

####1. What's the difference between rendering and redirecting? What's the impact with regards to instance variables, view templates?

Rendering displays a view template that accesses the instance variables available in that action. Therefore, instance variables must be declared in that action before the render will work. Redirecting will send a new request to the browser based on the route path that was provided. In this case, the instance variables in that action are not related to the redirected view.

####2. If I need to display a message on the view template, and I'm redirecting, what's the easiest way to accomplish this?

You can use flash, which saves the message with a session. The message will be displayed on your next action and will be removed after that. flash[:message] = 'Your account was created.' redirect_to :back

@kangkyu
kangkyu / gist:962746a4ca2a1110d711
Created April 29, 2015 23:22
create a new repository on the command line
git clone https://github.com/kangkyu/list-of-hamburger-restaurants.git
cd list-of-hamburger-restaurants
echo "# list-of-hamburger-restaurants" >> README.md
git add README.md
git commit -m "first commit"
git push -u origin master
@kangkyu
kangkyu / gist:2b1f9ed1b6ad26cfa6a4
Created February 10, 2015 20:35
html link buttons
<form action="http://google.com">
<input type="submit" value="Go to Google">
</form>
<a href="http://google.com">Go to Google</a>
@kangkyu
kangkyu / gist:107e375ec32f4c937f27
Last active August 29, 2015 14:14
9 digit password generation
(0..9).to_a + ('a'..'z').to_a + ('A'..'Z').to_a + %w(! @ # $ % ^ & * < > ?)
a = _
a.shuffle.pop(9).join
@kangkyu
kangkyu / gist:90bda70e68af80b6274b
Created February 2, 2015 21:06
dismissible form error message in Rails
- if @task.errors.any?
= content_tag(:div, class: ["alert", "alert-danger", "alert-dismissible"], role: "alert", id: "error-explanation") do
= content_tag(:button, class: "close", type: "button", "data-dismiss"=> "alert") do
= content_tag(:span, escape_once("&times;"), "aria-hidden"=> "true")
= content_tag(:span, "Close", class: "sr-only")
%p= pluralize(@task.errors.count, "error") + " prohibited this user from being saved"
%ul
- @task.errors.full_messages.each do |msg|
%li= msg