Skip to content

Instantly share code, notes, and snippets.

View CelesteComet's full-sized avatar

Bruce Wong CelesteComet

View GitHub Profile
def to_currency(string)
dollarified = ""
# returns dollars and cents in string format
dollars = string.split(".")[0].to_s
cents = string.split(".")[1]
# .23
if cents
cents = ("." + cents).to_f.round(2).to_s.split(".")[1].ljust(2,"0")
dollarified += ("." + cents)
number = "73167176531330624919225119674426574742355349194934
96983520312774506326239578318016984801869478851843
85861560789112949495459501737958331952853208805511
12540698747158523863050715693290963295227443043557
66896648950445244523161731856403098711121722383113
62229893423380308135336276614282806444486645238749
30358907296290491560440772390713810515859307960866
70172427121883998797908792274921901699720888093776
65727333001053367881220235421809751254540594752243
52584907711670556013604839586446706324415722155397
@CelesteComet
CelesteComet / capybara cheat sheet
Created July 4, 2017 05:00 — forked from zhengjia/capybara cheat sheet
capybara cheat sheet
=Navigating=
visit('/projects')
visit(post_comments_path(post))
=Clicking links and buttons=
click_link('id-of-link')
click_link('Link Text')
click_button('Save')
click('Link Text') # Click either a link or a button
click('Button Value')
@CelesteComet
CelesteComet / keyrepeat.shell
Created December 31, 2017 03:54 — forked from kconragan/keyrepeat.shell
Enable key repeat in Apple Lion for Sublime Text in Vim mode
# Mac OS X Lion introduced a new, iOS-like context menu when you press and hold a key
# that enables you to choose a character from a menu of options. If you are on Lion
# try it by pressing and holding down 'e' in any app that uses the default NSTextField
# for input.
#
# It's a nice feature and continues the blending of Mac OS X and iOS features. However,
# it's a nightmare to deal with in Sublime Text if you're running Vintage (Vim) mode,
# as it means you cannot press and hold h/j/k/l to move through your file. You have
# to repeatedly press the keys to navigate.
class ChannelChannel < ApplicationCable::Channel
def subscribed
stream_from "channel_#{params[:channel_name]}"
end
end
require_relative "heap"
class Array
def heap_sort!
# Create a heap
heap = BinaryMinHeap.new
# make an array to keep the sorted elements
sorted = []
def googleCard(cards):
end = None
dic = {}
for card in cards:
currentCard = card
if end is None:
end = currentCard + 5
@CelesteComet
CelesteComet / cpfValidator.js
Created May 3, 2018 23:46
CPF Validation for Brazil
function cpfValidate(str) {
let match = str.match(/^(\d{9})-(\d{2})$/);
if (!match) { return false }
// If in the correct format
let firstSetString = match[1];
let secondSetString = match[2];
let sum = 0;
for (let i = 0; i < firstSetString.length; i++) {
@CelesteComet
CelesteComet / credit-card-regex.md
Created February 25, 2019 20:20 — forked from michaelkeevildown/credit-card-regex.md
Credit Card Regex Patterns

Credit Card Regex

  • Amex Card: ^3[47][0-9]{13}$
  • BCGlobal: ^(6541|6556)[0-9]{12}$
  • Carte Blanche Card: ^389[0-9]{11}$
  • Diners Club Card: ^3(?:0[0-5]|[68][0-9])[0-9]{11}$
  • Discover Card: ^65[4-9][0-9]{13}|64[4-9][0-9]{13}|6011[0-9]{12}|(622(?:12[6-9]|1[3-9][0-9]|[2-8][0-9][0-9]|9[01][0-9]|92[0-5])[0-9]{10})$
  • Insta Payment Card: ^63[7-9][0-9]{13}$
  • JCB Card: ^(?:2131|1800|35\d{3})\d{11}$
  • KoreanLocalCard: ^9[0-9]{15}$
@CelesteComet
CelesteComet / how-to-copy-aws-rds-to-local.md
Created May 19, 2019 06:41 — forked from syafiqfaiz/how-to-copy-aws-rds-to-local.md
How to copy production database on AWS RDS(postgresql) to local development database.
  1. Change your database RDS instance security group to allow your machine to access it.
    • Add your ip to the security group to acces the instance via Postgres.
  2. Make a copy of the database using pg_dump
    • $ pg_dump -h <public dns> -U <my username> -f <name of dump file .sql> <name of my database>
    • you will be asked for postgressql password.
    • a dump file(.sql) will be created
  3. Restore that dump file to your local database.
    • but you might need to drop the database and create it first
    • $ psql -U <postgresql username> -d <database name> -f <dump file that you want to restore>
  • the database is restored