Skip to content

Instantly share code, notes, and snippets.

create new rails app:
$ rails new store_name -d postgresql
in postgres:
$ psql -U postgres
$ create role store_name login createdb;
create databases:
@0xGGGGG
0xGGGGG / rebazer.sh
Created April 23, 2013 12:08
a bash script to make rebasing default on git-pull
#!/bin/bash
# Makes rebasing default on git-pull
# Run it on the working-git-directory
echo "Existing branch's default action is being updated"
for file in $(find . -type d -name ".git")
do
LENGTH=${#file}
PRPATH="${file:0:LENGTH-4}"
pushd $PRPATH
# Clone rbenv into ~/.rbenv
git clone [email protected]:sstephenson/rbenv.git ~/.rbenv
# Add rbenv to your PATH
# NOTE: rbenv is *NOT* compatible with rvm, so you'll need to
# remove rvm from your profile if it's present. (This is because
# rvm overrides the `gem` command.)
echo 'export PATH="$HOME/.rbenv/bin:$HOME/.rbenv/shims:$PATH"' >> ~/.bash_profile
exec $SHELL
@0xGGGGG
0xGGGGG / doctest_test.ex
Last active December 18, 2015 21:19
doctest not working for nonmatching function clause.
defmodule ListExtensions do
@moduledoc false
@doc """
Traverses all of the elements in given list
and then sums the result and returns it.
Does not accept types other than list.
### Examples
@0xGGGGG
0xGGGGG / application_helper.rb
Created August 26, 2013 12:23
render respecting subdomains.
module ApplicationHelper
def render_respecting_subdomain(options = nil, extra_options = {}, &block)
raw render(sanitized_options_from(options, request.subdomain), extra_options, &block)
rescue ActionView::MissingTemplate
raw render(sanitized_options_from(options, "default"), extra_options, &block)
end
def sanitized_options_from(args, subdomain = "")
return args unless subdomain.present?
@0xGGGGG
0xGGGGG / arel_duplicates.rb
Created November 10, 2013 11:53
arel duplicates
User
.where(
phone: User
.select('phone, count(phone)')
.group('phone')
.having('count(phone) > 1')
.select{|u| u.phone.present?}
.map(&:phone) )
.select([:id, :phone, :email, :fullname])
.includes(:items)
.logo {
background: url("logo.png") no-repeat;
}
@media (min--moz-device-pixel-ratio: 1.3),
(-o-min-device-pixel-ratio: 2.6 / 2),
(-webkit-min-device-pixel-ratio: 1.3),
(min-device-pixel-ratio: 1.3),
(min-resolution: 1.3dppx) {
.logo {
@0xGGGGG
0xGGGGG / 1_chronal_calibration.ex
Last active December 2, 2018 21:01
#AdventOfCode 2018 #elixir #elixirlang
defmodule ChronalCalibration do
def calc_result(stream), do: Enum.sum(stream)
def find_first_redundant(stream) do
Stream.cycle(stream)
|> Stream.scan({0, MapSet.new([0])}, &collect_step/2)
|> Stream.filter(&redundant?/1)
|> Stream.map(fn {elem, _} -> elem end)
|> Enum.take(1)
|> Enum.at(0)
@0xGGGGG
0xGGGGG / 2_inventory_management.ex
Last active December 2, 2018 21:12
#AdventOfCode 2018 #elixir #elixirlang
defmodule InventoryManagement.Checksum do
def checksum(stream) do
stream
|> Stream.map(&String.trim/1)
|> Stream.map(&count_occurances/1)
|> Enum.reduce([two: 0, three: 0], &collect_each/2)
|> Enum.reduce(1, fn {_, val}, acc -> val * acc end)
end
defp collect_each([two: item_two, three: item_three], two: two, three: three) do
@0xGGGGG
0xGGGGG / 3_spoils_of_fabric.ex
Created December 3, 2018 22:14
#AdventOfCode 2018 #elixir #elixirlang
defmodule SpoilsOfFabric do
def count_overlaps(stream) do
stream
|> Stream.map(&cleanup/1)
|> Stream.map(&to_grid_positions/1)
|> Enum.reduce(%{}, &count_positions/2)
|> Enum.reduce(0, &count_overlaps/2)
end
def detect_sacred_fabric(stream) do