Skip to content

Instantly share code, notes, and snippets.

@adrdra
adrdra / Convert .mov or .MP4 to .gif.md
Created May 4, 2022 15:42 — forked from SheldonWangRJT/Convert .mov or .MP4 to .gif.md
Convert Movie(.mov) file to Gif(.gif) file in one command line in Mac Terminal

This notes is written by Sheldon. You can find me with #iOSBySheldon in Github, Youtube, Facebook, etc.

Need

Convert .mov/.MP4 to .gif

Reason

As a developer, I feel better to upload a short video when I create the pull request to show other viewers what I did in this PR. I tried .mov format directly got after finishing recording screen using Quicktime, however, gif offers preview in most web pages, and has smaller file size.

This is not limited to developer, anyone has this need can use this method to convert the files.

@adrdra
adrdra / vim.txt
Created September 26, 2018 10:08
Vim
* $ -> go to end of file
* x -> remove char
* :%s/\\//g -> remove `\`
* :%s/<E2><82><AC>/€/g
* :%!python -m json.tool -> pretty json
@adrdra
adrdra / formatters.rb
Last active April 24, 2018 10:32
Formatter
arr = [{ lol: 'lol', mdr: 'mdr' }]
def transform_array(list, formatters = {})
return list if formatters.empty?
list.map { |item|
formatters.reduce(item.dup) { |dup, (key, formatter)|
dup[key] = formatter === item.public_send(:[], key)
dup
}
@adrdra
adrdra / active_record_objects_autosave.md
Created May 5, 2017 14:07 — forked from demisx/active_record_objects_autosave.md
When Active Record Child Objects are Autosaved in Rails

belongs_to:

  1. Assigning an object to a belongs_to association does not automatically save the object. It does not save the associated object either.

has_one:

  1. When you assign an object to a has_one association, that object is automatically saved (in order to update its foreign key).
  2. In addition, any object being replaced is also automatically saved, because its foreign key will change too
  3. If either of these saves fails due to validation errors, then the assignment statement returns false and the assignment itself is cancelled.
  4. If the parent object (the one declaring the has_one association) is unsaved (that is, new_record? returns true) then the child objects are not saved. They will automatically when the parent object is saved.
# Precompile any file in the assets folder
# This fix the bootstrap compilation error
# @see "http://stackoverflow.com/questions/9915950/bootstrap-sass-undefined-variable-baselineheight"
Rails.application.config.assets.precompile += [/^[-_a-zA-Z0-9]*\..*/]
We can make this file beautiful and searchable if this error is corrected: No commas found in this CSV file in line 0.
region_name;department_number;department_name
Rhône-Alpes;1;Ain
Picardie;2;Aisne
Corse;20;Corse-du-Sud
Corse;20;Haute-Corse
Auvergne;3;Allier
Provence-Alpes-Côte d'Azur;4;Alpes-de-Haute-Provence
Provence-Alpes-Côte d'Azur;5;Hautes-Alpes
Provence-Alpes-Côte d'Azur;6;Alpes-Maritimes
Rhône-Alpes;7;Ardèche

Introduction to ES6 Features

##Arrows functions Arrows functions are shorthand functions using =>syntax. They support block bodies or expression body wich return the value of the expression.

Arrows function have their own context. So using this in arrows function will not refer to his prototype.

// ES5
function addOne(x) {
	return x + 1;
@adrdra
adrdra / populate_concern.rb
Created March 24, 2016 18:23
Populate concern to populate data from the body params.
module PopulateConcern
extend ActiveSupport::Concern
# ([String, ...]) => {}
def populate(attributes)
return self if attributes.blank?
to_populate = []
attributes.each do |attr|
to_populate.push(attr) if self.respond_to?(attr)
end
@adrdra
adrdra / Rails_advanced.md
Created December 3, 2015 11:21
Rails clase advanced

Rails advanced

Before Filters

Est un peu comme les before save des models mais pour les controller

Dans le cas où on a une partie connecté

Donc une before_action :require_login