Skip to content

Instantly share code, notes, and snippets.

@rstacruz
rstacruz / index.md
Last active November 3, 2023 09:56
Rails models cheatsheet

Rails Models

Generating models

$ rails g model User

Associations

belongs_to

has_one

@g3d
g3d / gist:2709563
Last active February 7, 2024 15:21 — forked from saetia/gist:1623487
Clean Install – OS X 10.11 El Capitan
@andreiz
andreiz / classifier.php
Last active July 12, 2022 12:50
A simple example of logistic regression via gradient descent in PHP.
<?php
error_reporting(E_ALL);
define('NUM_FEATURES', 3);
// My dataset describes cities around the world where I might consider living.
// Each sample (city) consists of 3 features:
// * Feature 1: average low winter temperature in the city
// * Feature 2: city population, in millions
@levi
levi / riot_esports_api.md
Last active July 8, 2024 22:51
Riot LoL eSports Unofficial API Documentation
// Playground - noun: a place where people can play
import Foundation
extension NSTimeInterval {
var seconds: NSTimeInterval {
return self
}
var minutes: NSTimeInterval {
@pricees
pricees / value_investing.rb
Last active June 4, 2017 13:08
Value Investing (CROIC)
# Margins of Safety
# 30% > $ 10B
# 50% - 30% for $1-10B Market Cap
# > 50% for < $1B
# Owner's Earnings
# Read more: http://www.oldschoolvalue.com/blog/valuation-methods/working-capital-free-cash-flow-fcf/#ixzz3O1Egljwo
# Owner earnings = Net income + depreciation & amortization +/- one-time items +/- changes in working capital - capital expenditures
def owner_earnings # Better than free cash flow
@jasiek
jasiek / isin_validator.rb
Created June 23, 2015 15:15
ISIN validation in Ruby
class IsinValidator < ActiveModel::Validator
CHARS = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'
def validate(record)
value = record[:isin_cusip]
return if value.blank?
digits = value.upcase.chars.collect { |c| CHARS.index c }
digits = digits.join.chars.collect { |c| c.to_i }
actual_check_digit = digits.pop

How to iOS

Dear iOS Developer,

These are the things you might take into account when developing rock-solid iOS apps.

Writing better code makes you happy and will make your employer, teammates, and even customers happier in the mid-long term.

Please remember

@hadees
hadees / arel_helpers.rb
Created March 5, 2016 05:41
Arel Helpers
module ArelHelpers
extend self
def self.included(base)
base.extend self
end
def asterisk(arel_table_or_model)
arel_table, columns = case arel_table_or_model
when Arel::Table
@syafiqfaiz
syafiqfaiz / how-to-copy-aws-rds-to-local.md
Last active June 22, 2024 20:31
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