Skip to content

Instantly share code, notes, and snippets.

View romchambe's full-sized avatar

Romain Chambe romchambe

  • Bayonne
View GitHub Profile
export class MainLayout extends React.Component {
dimensionsUpdatePoll: any = null;
constructor(props){
super(props);
this.state = {
width: 0,
height: 0
}
this.lastCheck = Date.now()
@romchambe
romchambe / javascript.md
Last active November 22, 2018 09:55
A gist on non obvious stuff in Javascript

Classic function statements

See source article

In depth analysis of functions mechanism in JS

Function prototype

Function are objects in JS and hence they have a prototype. The advantage of function being objects is that they can be easily passed as arguments to other functions or objects. There are 3 main methods in Function's prototype:

  • .call() and .apply(): they do significantly the same thing, ie executing a function while letting you specify a different 'this' than the natural one (that you pass in the first argument). The difference between the two is that arguments in addition to this are passed individually in .call() and as an array in .apply().
@romchambe
romchambe / react-native-setup.md
Last active January 5, 2019 16:55
React Native setup (development environment and linting)

Index

Android setup

  • Java 8 must be installed on the computer (NB: later version than 8 might not work - casks are applications with a GUI, the first command is necessary so that you can install alternate vesions of a given cask):
@romchambe
romchambe / _checkbox.scss
Created June 9, 2018 14:33
Commodity styles and components to be reused in projects
/* So that a 'component style file' is not compiled to css in a separate file by npm watch, it needs to start with an underscore */
$hover: #eee;
$checked: #20c997;
$unchecked: white;
/* Customize the label (the checkbox-area) */
.checkbox-area {
position: relative;
cursor: pointer;
@romchambe
romchambe / react_rails_api_setup.md
Last active July 20, 2018 12:02
Setup a React app with a Rails API

Initialization

  1. Set the Rails API up as described in this guide

  2. Create a React client app using $ create-react-app inside the root folder of the Rails app

  3. Set up local servers using the Foreman gem

    • add gem foremanin the development group of your Gemfile and run command $ bundle install
    • Create a Procfile.dev file and add the following lines so that both the rails server and the react server start (on different ports) when running $ foreman start -f Procfile.dev:
@romchambe
romchambe / Gemfile
Last active July 18, 2018 14:21
API Gemfile
source 'https://rubygems.org'
gem 'rails', '~> 5.1.6' # Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'puma', '~> 3.7' # Use Puma as the app server
gem 'jbuilder', '~> 2.5' # Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'redis', '~> 4.0' # Use Redis adapter to run Action Cable in production
gem 'bcrypt', '~> 3.1.7' # Authentication
gem 'jwt' # encoding and decoding of HMACSHA256 tokens available in the Rails application
gem 'pg', '~> 0.20.0' # Database
gem 'rack-cors', require: 'rack/cors' # Allow Cross Origin Ressource Sharing

Setup

  1. Install Devise in a Rails app (after making sure it is in your Gemfile): $ rails g devise:install
  2. Generate standard Devise models: $ rails g devise User
  3. Generate standard Devise views: $ rails g devise:views
  4. Enforce strong parameters

Enforcing strong parameters

The following lines needs to be copied in the ApplicationController, so that no additional params are passed in Devise fields:

@romchambe
romchambe / Gemfile
Last active May 29, 2018 09:52
Default Gemfile
source 'https://rubygems.org'
# ------------------------------------- Universal gems -----------------------------------------------
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 5.1.4'
# Use Puma as the app server
gem 'puma', '~> 3.7'
# Websockets
@romchambe
romchambe / rails_models_cheatsheet.md
Last active September 18, 2018 13:53
Setup of SSL certificate on Heroku with Gandi

SSL setup: https://vimeo.com/209534466

Creating a join table

rails g migration CreateJoinTableGameInvitesInvitees game_invites invitees

  • Models linked together must be in alphabetical order when naming the migration file
  • The columns can be given any names as long as they are correctly associated in the model file:
has_and_belongs_to_many :invitees, class_name: 'User', foreign_key: 'invitee_id', #the associated column and the alien model
                        join_table: 'game_invites_invitees', #name of the join table
                        association_foreign_key: 'game_invite_id' #the name of the domestic model in the join table
@romchambe
romchambe / rails_app_setup.md
Last active May 29, 2018 13:06
Setup of a Rails app

Setup of a Rails app

Checklists

Rails app initialisation checklist

  1. Create a new Rails app: $ rails new my_app
  • add --api flag to create an API-only application