Skip to content

Instantly share code, notes, and snippets.

View samnang's full-sized avatar
🚀

Samnang Chhun samnang

🚀
View GitHub Profile
@samnang
samnang / cursor_based_pagination.rb
Created March 10, 2019 06:18
pseudocode of cursor based pagination in Rails
class CursorPaginator
attr_reader :cursor_keys, :max_items, :limit
CURSOR_DIRECTIONS = {
after: :gt,
before: :lt
}.freeze
def initialize(options = {})
@cursor_keys = options.fetch(:cursor_keys, id: :asc)
set -xe
EB_SCRIPT_DIR=$(/opt/elasticbeanstalk/bin/get-config container -k script_dir)
. $EB_SCRIPT_DIR/use-app-ruby.sh
gem update --system
<Response>
<Say voice="alice">Thanks for trying our documentation. Enjoy!</Say>
<Play>https://demo.twilio.com/docs/classic.mp3</Play>
</Response>
@samnang
samnang / aws-console
Created February 19, 2018 08:15 — forked from wearethefoos/aws-console
AWS Elastic Beanstalk
#!/usr/bin/env bash
#
# Rails console script that can be run on AWS Elastic Beanstalk.
#
# Run this script from the app dir (/var/app/current) as root (sudo script/aws-console)
#
set -xe
EB_SCRIPT_DIR=$(/opt/elasticbeanstalk/bin/get-config container -k script_dir)
# Compile source #
###################
*.com
*.class
*.dll
*.exe
*.o
*.so
# Packages #
@samnang
samnang / README-Template.md
Created November 13, 2017 16:41 — forked from PurpleBooth/README-Template.md
A template to make good README.md

Project Title

One Paragraph of project description goes here

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.

Prerequisites

@samnang
samnang / 1_decorator.rb
Created September 15, 2013 03:21
Decorator vs Form Object vs Service Object?
class FacebookCommentNotifer
def initialize(comment)
@comment = comment
end
def save
@comment.save && post_to_wall
end
private
@samnang
samnang / .md
Last active February 17, 2017 21:21
Guard clause vs Control Structures in #Elixir?

1. Using guard

defmodule MyList do
  def max(list), do: _max(list, nil)

  defp _max([], max_value), do: max_value
  defp _max([head | tail], nil), do: _max(tail, head)

  # using guard
  defp _max([head | tail], max_value) when max_value < head, do: _max(tail, head)
@samnang
samnang / rails31init.md
Created September 3, 2011 16:27 — forked from docwhat/rails31init.md
Rails 3.1 with Rspec, Factory Girl, Haml, Simple Form, Database Cleaner, Spork, and Guard

Install Rails 3.1

gem install rails

generate new app, skipping Test::Unit file generation

rails new my_app -T

Set up Gemfile

@samnang
samnang / heroku-environments
Created August 11, 2016 19:48 — forked from csexton/heroku-environments
Heroku Environment CLI Wrapper
#!/usr/bin/env ruby
# Heroku enviroment helper script
#
# This is to streamline using differnt heroku enviroments from one repo.
# Symlink this file to an envroment name (as set by the git-remote name), then
# when running that symlink the script will look up the name in the git config
# and use that remote as the heroku name.
#
# Setup: