Skip to content

Instantly share code, notes, and snippets.

@gabriel-dehan
gabriel-dehan / baseEntity.ts
Last active February 27, 2023 14:34
Gives an `EntityPartial<T>` type that can be used with a typeorm entity as a contructor input type
import { CreateDateColumn, PrimaryGeneratedColumn, UpdateDateColumn } from 'typeorm';
import { EntityPartial } from 'tools/types/entity';
export class BaseEntity<T> {
constructor(input?: EntityPartial<T>) {
this.setAttributes(input);
}
@PrimaryGeneratedColumn()
readonly id!: number;
@gabriel-dehan
gabriel-dehan / README.md
Created February 16, 2023 23:05
A case against non-null assertion operator

The non-null assertion operator (!) in TypeScript allows you to assert that a value is not null or undefined, even if the type of the value allows for these values. While the non-null assertion operator can be useful in some situations, abusing it can be dangerous because it can lead to runtime errors and bugs that are difficult to trace. Here are some reasons why the non-null assertion operator can be dangerous if you abuse it:

  • Type safety: Using the non-null assertion operator can bypass TypeScript's type checking and compromise type safety. This can lead to runtime errors when the code is executed, especially if the type assumptions are incorrect.
  • Null pointer exceptions: Using the non-null assertion operator can result in null pointer exceptions if the value is actually null or undefined at runtime. These exceptions can be difficult to debug and can lead to application crashes or unexpected behavior.
  • Maintenance: Using the non-null assertion operator can make code more difficult to maintain and mod
@gabriel-dehan
gabriel-dehan / enumToObject.ts
Created May 28, 2020 16:00
enumToObject.ts
function enumToObject<T extends Record<string, unknown>, V>(enumObject: T, value: V): Record<keyof T, V> {
const obj: Partial<Record<keyof T, V>> = {};
Object.keys(enumObject).forEach((key) => {
obj[key as keyof T] = value;
});
return obj as Record<keyof T, V>;
}
@gabriel-dehan
gabriel-dehan / resolveProptypes.js
Last active November 29, 2019 10:47
Given a component, returns an object with data about all props (what's the type, is it required, what are the options)...
import checkPropTypes from 'check-prop-types';
import pickBy from 'lodash/pickBy';
const getPropsSchema = (component) => {
if (component.type.propTypes) {
return Object.keys(component.type.propTypes).map((propName) => resolvePropType(component.type.propTypes, propName));
}
return [];
};
@gabriel-dehan
gabriel-dehan / Elastic.md
Created May 29, 2018 17:23
Elasticsearch install ubuntu > 16.04

Elasticsearch - Ubuntu

Prerequisites

You will need to install Java if you don't already have it.

$ sudo apt-get update
$ sudo apt-get install default-jre
$ sudo apt-get install default-jdk
$ sudo add-apt-repository ppa:webupd8team/java
  • What do I do after merging a branch ? What does my team need to do ?

  • I created a new branch but I forgot to pull master before Commit all your changes (git add ., git commit) Go back to master git checkout master Update master git pull origin master Go back to your branch git checkout my-branch Take all the changes from master and add them to my branch git merge master Fix conflics & Commit if needed

.card-tags {
position: absolute;
width: 80%;
padding: 8px;
span {
background: $blue;
font-size: .7em;
padding: 2px 4px;
border-radius: 3px;
@gabriel-dehan
gabriel-dehan / form_for_explanation.md
Last active May 17, 2018 16:13
How does form_for works

Here are some explanations on "form_for" :

How does form_for works:

<%= form_for(@pet) do |f| %>
  ...
<% end %>
@gabriel-dehan
gabriel-dehan / bash.rb
Created February 26, 2018 16:40
failed to load command: webpack
rails webpacker:install
heroku buildpacks:add heroku/nodejs -i 1
heroku buildpacks:add --index 2 https://github.com/heroku/heroku-buildpack-ruby
compute = (allocation, price, force_price: false) ->
if force_price
Math.max(Math.max(force_price, MINIMUM_QUOTE_ORDER_AMOUNT/price), MINIMUM_BASE_ORDER_AMOUNT)
else
Math.max(Math.max(allocation/price, MINIMUM_QUOTE_ORDER_AMOUNT/price), MINIMUM_BASE_ORDER_AMOUNT)