<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom"><title>Romain Pellerin's Blog - Computers</title><link href="https://romainpellerin.eu/" rel="alternate"></link><link href="//romainpellerin.eu/feeds/categories/computers/atom.xml" rel="self"></link><id>https://romainpellerin.eu/</id><updated>2024-07-28T18:00:00+02:00</updated><entry><title>Airtags for Android</title><link href="https://romainpellerin.eu/airtags-for-android.html" rel="alternate"></link><published>2024-07-28T18:00:00+02:00</published><updated>2024-07-28T18:00:00+02:00</updated><author><name>Romain Pellerin</name></author><id>tag:romainpellerin.eu,2024-07-28:/airtags-for-android.html</id><summary type="html">&lt;p&gt;All about the equivalent of Apple's airtags for Android&lt;/p&gt;</summary><content type="html">&lt;p&gt;Years after Apple launched the Airtags, Android is finally getting its long awaited counterpart, in the form of Google's "Find My Device" network.&lt;/p&gt;
&lt;p&gt;Yet, before this new standard, many companies had released their tags with their own networks, that would only work with their own app. Needless to say, the density of their networks is limited hence hindering their finding capabilities. Now that Google has released its network, these same companies are also launching new products that work with it. So essentially this means that besides the official AirTags from Apple, most other products either work exclusively with Apple, exclusively with Google, or exclusively with their prorietary apps. Here's a short article about what tags work with Google's network.&lt;/p&gt;
&lt;h1 id="chipolo-one-point"&gt;Chipolo ONE Point&lt;/h1&gt;
&lt;p&gt;&lt;a href="https://chipolo.net/en/products/chipolo-one-point"&gt;Currently priced at 34 euros&lt;/a&gt;, discount codes can easily be found on Reddit. They do not support UWB (Ultra WideBand) but I'm not sure it's a big deal... Is this precision-finding feature really useful for my usages? I intend to track my luggage, not my keys...&lt;/p&gt;
&lt;h1 id="pebblebee-clip-for-android"&gt;Pebblebee Clip for Android&lt;/h1&gt;
&lt;p&gt;&lt;a href="https://pebblebee.com/products/clip-for-android"&gt;Same price range, currently at 33.95 euros&lt;/a&gt;. They seem to be super similar to the Chipolo one. Again, no support for UWB.&lt;/p&gt;
&lt;h1 id="moto-tag"&gt;Moto Tag&lt;/h1&gt;
&lt;p&gt;&lt;a href="https://www.motorola.com/us/moto-tag"&gt;They were just announced but they haven't been released yet.&lt;/a&gt; They will be the first tags to support USW. I might give them a chance in the future, after reviews start popping up on the Web.&lt;/p&gt;</content><category term="Computers"></category><category term="android"></category><category term="google"></category><category term="airtag"></category></entry><entry><title>Chargers</title><link href="https://romainpellerin.eu/chargers.html" rel="alternate"></link><published>2023-11-17T20:00:00+01:00</published><updated>2024-02-04T13:07:00+01:00</updated><author><name>Romain Pellerin</name></author><id>tag:romainpellerin.eu,2023-11-17:/chargers.html</id><summary type="html">&lt;p&gt;Everything you ever wanted to know about chargers&lt;/p&gt;</summary><content type="html">&lt;p&gt;The year is 2023 and chargers have gotten incredibly complex and powerful. As I was browsing the web, trying to get my hands on a good one that would allow me to charge any device, I though it deserved an article and some explanations.&lt;/p&gt;
&lt;h1 id="usb-1x-usb-2x-usb-3x-usb4"&gt;USB 1.x, USB 2.x, USB 3.x, USB4&lt;/h1&gt;
&lt;p&gt;From &lt;a href="https://en.wikipedia.org/wiki/USB"&gt;Wikipedia&lt;/a&gt;, these are specifications of "an industry standard that allows data exchange and delivery of power between many various types of electronics".&lt;/p&gt;
&lt;p&gt;USB 3 is notoriously known for its blue port. "USB4 mandates the exclusive use of the Type-C connector and USB Power Delivery (USB-PD) specification", says &lt;a href="https://en.wikipedia.org/wiki/USB4"&gt;Wikipedia&lt;/a&gt;.&lt;/p&gt;
&lt;h1 id="usb-c-1-usb-c-2"&gt;USB-C 1 &amp;amp; USB-C 2&lt;/h1&gt;
&lt;p&gt;Two different revisions of the "new" USB-C connector. The revision 2 comes with newer capabilities (for instance enhanced power delivery). &lt;a href="https://en.wikipedia.org/wiki/USB-C#USB_Type-C_cable_and_connector_specifications"&gt;See Wikipedia&lt;/a&gt; for more information.&lt;/p&gt;
&lt;h1 id="pd-power-delivery"&gt;PD (Power Delivery)&lt;/h1&gt;
&lt;p&gt;The &lt;a href="https://www.usb.org/usb-charger-pd"&gt;official page&lt;/a&gt; says it best:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;USB has evolved from a data interface capable of supplying limited power to a primary provider of power with a data interface. Today many devices charge or get their power from USB. USB has become a ubiquitous power socket for many small devices such as cell phones, tablets, portable speakers and other hand-held devices. Users need USB to fulfil their requirements not only in terms of data but also to provide power to, or charge, their devices simply, often without the need to load a driver, in order to carry out “traditional” USB functions.&lt;/p&gt;
&lt;p&gt;The USB Power Delivery (USB PD) Specification enables the maximum functionality of USB by providing more flexible power delivery along with data over a single cable. Its aim is to operate with and build on the existing USB ecosystem.&lt;/p&gt;
&lt;p&gt;Announced in 2021, the USB PD Revision 3.1 specification is a major update to enable delivering up to 240W of power over full featured USB Type-C® cable and connector. Prior to this update, USB PD was limited to 100W using a solution based on 20V using USB Type-C cables rated at 5A. The USB Type-C specification has also been updated to Release 2.1 to define 240W cable requirements, and with the updated USB PD protocol and power supply definition, this extends the applicability of USB power delivery to a large number of applications where 100W wasn't adequate.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;In other words, it's a capability to deliver more power through USB, so as to charge devices.&lt;/p&gt;
&lt;h1 id="pps-programmable-power-supply"&gt;PPS (Programmable Power Supply)&lt;/h1&gt;
&lt;p&gt;From &lt;a href="https://en.wikipedia.org/wiki/USB_hardware#USB_Power_Delivery"&gt;Wikipedia&lt;/a&gt;:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;The USB Power Delivery specification revision 3.0 defines an optional Programmable Power Supply (PPS) protocol that allows granular control over VBUS power, allowing a range of 3.3 to 21 V in 20 mV steps to facilitate constant-current or constant-voltage charging.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h1 id="iq3-poweriq-30-piq-30-or-version-4"&gt;iQ3 / PowerIQ 3.0 / PIQ 3.0 (or version 4...)&lt;/h1&gt;
&lt;p&gt;From &lt;a href="https://www.reddit.com/r/anker/comments/c16oci/power_iq30_vs_pd/"&gt;Reddit&lt;/a&gt;:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;PowerIQ 3.0 is Anker's version of Quick Charge 4+&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Also from &lt;a href="https://www.reddit.com/r/anker/comments/wk8r7k/anker_power_iq_40_means_usb_pd_31_with_pps/"&gt;another Reddit page&lt;/a&gt;:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Power IQ 4.0 means that the device supports USB power delivery 3.1 and all Power IQ 4.0 devices include PPS.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h1 id="quick-charge-qc"&gt;Quick Charge (QC)&lt;/h1&gt;
&lt;p&gt;From &lt;a href="https://en.wikipedia.org/wiki/Quick_Charge"&gt;Wikipedia&lt;/a&gt;:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Quick Charge (QC) is a proprietary battery charging protocol developed by Qualcomm, used for managing power delivered over USB, mainly by communicating to the power supply and negotiating a voltage. Quick Charge is supported by devices such as mobile phones which run on Qualcomm SoCs, and by some chargers; both device and charger must support QC, otherwise QC charging is not attained.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h1 id="gan-gan-2-ganprime"&gt;GaN, GaN 2, GaNPrime&lt;/h1&gt;
&lt;p&gt;Different generations of Gallium Nitride chargers from Anker, from oldest to newest. Those chargers are generally smaller and cooler (less heat) than other non-GaN chargers. More info on &lt;a href="https://www.reddit.com/r/UsbCHardware/comments/134k7b7/what_is_the_difference_of_gan_charger_generations/"&gt;Reddit&lt;/a&gt;. Other brands manufacture GaN chargers, not just Anker.&lt;/p&gt;
&lt;h1 id="what-do-buy"&gt;What do buy&lt;/h1&gt;
&lt;p&gt;&lt;a href="https://amzn.eu/d/78cPjLm"&gt;Anker USB C Charger (Nano II 65W) USB-C 65W Pod 3-Port PPS Fast Charger, Compact USB-C Power Supply&lt;/a&gt; seems to be a good option, price-wise and feature-wise.&lt;/p&gt;
&lt;p&gt;For some extra euros, one can get PowerIQ 4: &lt;a href="https://amzn.eu/d/hWFc1K2"&gt;Anker USB C Charger, 735 (GaNPrime 65W) Fast and Compact 3-Port&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Ugreen is another great brand I would have considered.&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;That's it!&lt;/p&gt;</content><category term="Computers"></category><category term="charger"></category><category term="computer"></category><category term="laptop"></category><category term="smartphone"></category><category term="android"></category></entry><entry><title>Raspberry Pi NoIR camera module and IR LEDs</title><link href="https://romainpellerin.eu/raspberry-pi-noir-camera-module-and-ir-leds.html" rel="alternate"></link><published>2023-03-13T18:30:00+01:00</published><updated>2023-03-16T00:52:00+01:00</updated><author><name>Romain Pellerin</name></author><id>tag:romainpellerin.eu,2023-03-13:/raspberry-pi-noir-camera-module-and-ir-leds.html</id><summary type="html">&lt;p&gt;Seeing in the dark with the Raspberry Pi camera modules and some infrared LEDs&lt;/p&gt;</summary><content type="html">&lt;p&gt;Lately I've been looking into adding infrared LEDs to my Raspberry Pi, as I just purchased the latest &lt;a href="https://www.raspberrypi.com/products/camera-module-3/"&gt;camera module v3&lt;/a&gt;, in its NoIR (no infrared filter) edition.&lt;/p&gt;
&lt;h1 id="basic-knowledge-required"&gt;Basic knowledge required&lt;/h1&gt;
&lt;p&gt;Physics courses in high school took place like forever ago, I basically remembered nothing. So I had to dig it up a little bit and study basics again (Ohm's law for instance 😅).&lt;/p&gt;
&lt;h2 id="raspberry-pi"&gt;Raspberry Pi&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;It has 2 pins that output 5V, 2 pins that output 3.3V, a few "ground" pins, and the rest are GPIO pins, that can output 3.3V and are controllable.&lt;/li&gt;
&lt;li&gt;The Raspberry Pi can only supply a small current (about 60mA). The LEDs will want to draw more, and if allowed to they will burn out the Raspberry Pi. That's why we'll need to use a resistor. As a rule of thumb, any resistor equal or greater than 50Ω (Ohm) should suffice for one or more LEDs in series plugged on a 3.3V GPIO pin. More on that down below.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="multimeter"&gt;Multimeter&lt;/h2&gt;
&lt;p&gt;A tool to measure various things. The "A" (Ampere meter) plug acts as a closed circuit, so never put the test leads into the home sockets! The "V" (Voltmeter) plug acts as an open circuit.&lt;/p&gt;
&lt;h2 id="leds"&gt;LEDS&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;The anode is the long leg of a LED, where you connect the +. The cathode is the - (on the side where the diode has a flat).&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Extracts from &lt;a href="https://electronics.stackexchange.com/questions/10962/what-is-forward-and-reverse-voltage-when-working-with-diodes"&gt;stackoverflow.com&lt;/a&gt;:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;The &lt;strong&gt;forward voltage&lt;/strong&gt; is the voltage drop across the diode if the voltage at the anode is more positive than the voltage at the cathode (if you connect + to the anode).&lt;br&gt;
You will be using this value to calculate the power dissipation of the diode and the voltage after the diode.&lt;br&gt;
The &lt;strong&gt;reverse voltage&lt;/strong&gt; is the voltage drop across the diode if the voltage at the cathode is more positive than the voltage at the anode (if you connect + to the cathode).&lt;br&gt;
This is usually much higher than the forward voltage. As with forward voltage, a current will flow if the connected voltage exceeds this value.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;To paraphrase the last sentence, the forward voltage (&lt;em&gt;tension de seuil&lt;/em&gt; in French) is the minimum amount of volts needed to light up a LED. If you connect the anode to the - and supply more volts than the reverse voltage, you'll burn the LED out.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;"Forward voltage" and "voltage drop", two pieces of information usually found in LED specs, are &lt;a href="https://forum.arduino.cc/t/forward-voltage-vs-voltage-drop/634711"&gt;almost interchangeable words&lt;/a&gt;. The "voltage drop" is the "forward voltage" at the specified current (amperage, &lt;em&gt;intensité&lt;/em&gt; in French). If you increase the current (amperage), you'll increase the "voltage drop". That voltage drop varies depending on the current (amperage) and on the color of the LED, higher voltage = higher current (amperage). See the image further down below.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Other extracts from &lt;a href="https://electronics.stackexchange.com/questions/256336/does-led-brightness-change-with-voltage"&gt;stackoverflow&lt;/a&gt;:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;With an LED it's the amount of current flowing through it that determines how bright it is. Increasing the voltage increases the current, yes, but the region where that happens without the current getting too much is very small.&lt;br&gt;
So we control the current instead of the voltage, and take the forward voltage as a fixed value. By either including a resistor in the circuit to fill the gap between the supply voltage and the forward voltage, limiting the current in the process [...]&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;&lt;figure class="center"&gt;&lt;img alt="LED: amperage and voltage" src="https://romainpellerin.eu/images/led.png" /&gt;&lt;/figure&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Extracts from &lt;a href="https://www.ledsupply.com/blog/wiring-leds-correctly-series-parallel-circuits-explained/"&gt;LEDsupply.com&lt;/a&gt;:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Running a series circuit helps to provide the same amount of current to each LED. This means each LED in the circuit will be the same brightness and will not allow a single LED to hog more current than another.&lt;br&gt;
“The total voltage of the circuit is the sum of the voltages across each LED”. This means you have to supply, at minimum, the sum of the forward voltages of each LED.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;So if my series circuit, connected to the GPIO pins of my Raspberry Pi, supplies 3.3V, and I plug in 2 LEDS whose forward voltage is 1.5V, there will be 3V "consummed" and 0.3V "remaining".&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Extracts from &lt;a href="http://www.learningaboutelectronics.com/"&gt;LearningaboutElectronics.com&lt;/a&gt;:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;The Continuous Forward Current specification of an LED serves to tell you the maximum current that an LED can be fed continuously without being damaged or destroyed.&lt;br&gt;
The Peak Forward Current, IF(peak), specification of an LED serves to tell you the maximum current that an LED can be fed without being damaged or destroyed. &lt;/p&gt;
&lt;/blockquote&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="resistor-needed"&gt;Resistor needed&lt;/h3&gt;
&lt;p&gt;As seen above, with 2 LEDs in series, each with a forward voltage of 1.5V for 20mA, plugged on a GPIO pin supplying 3.3V, we need a resistor as follow:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;I = V/R
IF = (VS - VF) / R
# IF = forward current, VS = supplied voltage, VF = forward voltage
0.020 = (3.3 - 1.5 - 1.5) / R
R = (3.3 - 1.5 - 1.5) / 0.020 = 15 Ω
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Note that, if we shift our target amps from 20 to say 40mA to allow the LEDs to draw more current, their forward voltage will increase. Check the specs to know how much. &lt;strong&gt;Never aim higher than 60mA, as it's the maximum the Raspberry Pi can deliver.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Now if we have just one LED and aim for maximum current (60mA):&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;R = (3.3 - 1.5) / 0.060 = 30 Ω
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;That's why in the beginning of the article I wrote that 50 Ω is safe for almost all scenarios. 1.5V is among the lowest voltage values drawn by LEDs, since infrared LEDs are those that need the least. For a different color (blue for instance), the computation would most likely look like this, depending on the actual specs of course:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;R = (3.3 - 2.5) / 0.060 = 13.3 Ω
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;h1 id="what-i-ended-up-doing"&gt;What I ended up doing&lt;/h1&gt;
&lt;p&gt;In the end, I bought two &lt;a href="https://www.reichelt.de/de/en/ir-led-black-40-5-mm-sfh-4546-p146652.html"&gt;1.5V 5mm IR LEDs&lt;/a&gt; and a &lt;a href="https://www.reichelt.de/de/en/carbon-film-resistor-1-4-w-5-6-8-ohms-1-4w-6-8-p1452.html"&gt;6.8 Ohm resistor&lt;/a&gt;, that I soldered all together. The result is pretty nice, and it's working like a charm. By connecting it to a regular GPIO pin, I can programmatically turn it on and off.&lt;/p&gt;
&lt;figure class="center"&gt;
&lt;img src="https://romainpellerin.eu/images/raspberry-pi-noir-camera-module-and-ir-leds/ir-led-and-resistor.jpg" alt="A Raspberry Pi with two LEDs and a resistor" /&gt;
&lt;figcaption&gt;Before soldering&lt;/figcaption&gt;
&lt;/figure&gt;

&lt;figure class="center"&gt;
&lt;img src="https://romainpellerin.eu/images/raspberry-pi-noir-camera-module-and-ir-leds/ir-led-and-resistor-soldered.jpg" alt="Two LEDs and a resistor soldered" /&gt;
&lt;figcaption&gt;After soldering&lt;/figcaption&gt;
&lt;/figure&gt;

&lt;p&gt;Note that the LEDs I bought have a wavelength of 940 nm. I believe the camera with embedded LEDs I had before was 850 nm. 850 nm is visible by the human eye (dim red) while 940 is not at all. 940 also appears less bright on video than 850, from my experience, in pitch dark.&lt;/p&gt;
&lt;h1 id="others-who-did-it-before-me"&gt;Others who did it before me&lt;/h1&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="https://community.element14.com/products/raspberry-pi/raspberrypi_projects/b/blog/posts/testing-pi-noir-with-ir-leds"&gt;Testing Pi NoIR with IR LEDs&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;</content><category term="Computers"></category><category term="raspberry pi"></category><category term="camera"></category></entry><entry><title>Raspberry Pi and SSD</title><link href="https://romainpellerin.eu/raspberry-pi-and-ssd.html" rel="alternate"></link><published>2021-01-10T17:50:00+01:00</published><updated>2023-03-10T11:17:00+01:00</updated><author><name>Romain Pellerin</name></author><id>tag:romainpellerin.eu,2021-01-10:/raspberry-pi-and-ssd.html</id><summary type="html">&lt;p&gt;Resources on Raspberry Pis and SSDs&lt;/p&gt;</summary><content type="html">&lt;h1 id="ssds"&gt;SSDs&lt;/h1&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.berrybase.de/kingston-2-5-sata-ssd-a400-240gb"&gt;Kingston 2,5" SATA SSD A400 240GB&lt;/a&gt; (&lt;a href="https://jamesachambers.com/raspberry-pi-cheap-ssd-upgrade-30/"&gt;a full blog article here&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.amazon.com/Samsung-250GB-2-5-inch-Solid-State/dp/B078WQJXNF"&gt;Samsung EVO 860 250GB&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://storage.jamesachambers.com/popular/"&gt;Crucial BX500&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.raspberrypi.org/forums/viewtopic.php?p=1653853#p1653853"&gt;HP S600 120GB SSD&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.raspberrypi.org/forums/viewtopic.php?p=1503165&amp;amp;sid=ff8ab32436d61094b18ea26dd70618e4#p1503165"&gt;Other SSDs&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h1 id="sata-to-usb-30-adapters"&gt;SATA to USB 3.0 adapters&lt;/h1&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.berrybase.de/usb-3.0-adapterkabel/konverter-fuer-2-5-sata-festplatten-ssds"&gt;USB 3.0 Adapterkabel / Konverter für 2,5" SATA Festplatten &amp;amp; SSDs&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.amazon.com/dp/B0716JKJ68"&gt;ELUTENG 2.5 Inch SATA to USB 3.0 adapter&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://jamesachambers.com/raspberry-pi-cheap-ssd-upgrade-30/"&gt;StarTech 2.5" SATA to USB 3.0 adapter&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.raspberrypi.org/forums/viewtopic.php?p=1503165&amp;amp;sid=ff8ab32436d61094b18ea26dd70618e4#p1503165"&gt;Other adapters&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;</content><category term="Computers"></category><category term="raspberry pi"></category></entry><entry><title>How To Check The Integrity Of A Backup Folder</title><link href="https://romainpellerin.eu/how-to-check-the-integrity-of-a-backup-folder.html" rel="alternate"></link><published>2020-08-27T23:50:00+02:00</published><updated>2020-08-27T23:50:00+02:00</updated><author><name>Romain Pellerin</name></author><id>tag:romainpellerin.eu,2020-08-27:/how-to-check-the-integrity-of-a-backup-folder.html</id><summary type="html">&lt;p&gt;Checking the md5sum of files copied across two folders&lt;/p&gt;</summary><content type="html">&lt;p&gt;Recently, I made a backup copy of a folder that I copied over several devices. In the end, I wanted to make sure the various copies did not alter any of the files. Here's how to proceed:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="nb"&gt;cd&lt;/span&gt; &amp;lt;ORIGINAL FOLDER&amp;gt;
find . -type f &lt;span class="p"&gt;|&lt;/span&gt; sort &lt;span class="p"&gt;|&lt;/span&gt; &amp;gt; /tmp/original.files
&lt;span class="nb"&gt;cd&lt;/span&gt; &amp;lt;BACKUP FOLDER&amp;gt;
find . -type f &lt;span class="p"&gt;|&lt;/span&gt; sort &lt;span class="p"&gt;|&lt;/span&gt; &amp;gt; /tmp/backup.files

&lt;span class="c1"&gt;# You may not have copied all the files, so let&amp;#39;s only keep the common ones&lt;/span&gt;
comm -12 /tmp/original.files /tmp/backup.files &amp;gt; /tmp/common.files

&lt;span class="nb"&gt;cd&lt;/span&gt; &amp;lt;ORIGINAL FOLDER&amp;gt;
cat /tmp/common.files &lt;span class="p"&gt;|&lt;/span&gt; xargs -d&lt;span class="s1"&gt;&amp;#39;\n&amp;#39;&lt;/span&gt; md5sum &amp;gt; /tmp/original.md5sum
&lt;span class="c1"&gt;# -d&amp;#39;\n&amp;#39; so that filenames with space characters are handled&lt;/span&gt;
&lt;span class="nb"&gt;cd&lt;/span&gt; &amp;lt;BACKUP FOLDER&amp;gt;
md5sum --check /tmp/original.md5sum &lt;span class="c1"&gt;# Shows OK or FAILED for each file&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Hope that helps.&lt;/p&gt;</content><category term="Computers"></category><category term="linux"></category><category term="md5sum"></category><category term="git"></category></entry><entry><title>Playing With A Raspberry Pi Camera</title><link href="https://romainpellerin.eu/playing-with-a-raspberry-pi-camera.html" rel="alternate"></link><published>2020-06-01T02:50:00+02:00</published><updated>2022-09-24T12:11:00+02:00</updated><author><name>Romain Pellerin</name></author><id>tag:romainpellerin.eu,2020-06-01:/playing-with-a-raspberry-pi-camera.html</id><summary type="html">&lt;p&gt;What's possible with a Raspberry Pi camera&lt;/p&gt;</summary><content type="html">&lt;p&gt;Recently I've been playing with my old Raspberry Pi and a camera module (version 2) I bought a while ago. It turns out the camera is quite powerful and allowed me to create various types of videos or pictures. Here's what I've been able to do.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Note 1: In this article, I am using two commands that are meant to take photos or videos, natively installed on Rapsbian: &lt;code&gt;raspistill&lt;/code&gt; and &lt;code&gt;raspivid&lt;/code&gt;. For a complete user manual, follow &lt;a href="https://onlinelibrary.wiley.com/doi/pdf/10.1002/9781119415572.app2"&gt;this link&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Note 2: Don't forget to adjust the focus by rotating the lens (clockwise to focus on distant objects, anti-clockwise for close objects).&lt;/em&gt;&lt;/p&gt;
&lt;h1 id="a-timelapse-of-the-sky-at-night"&gt;A timelapse of the sky at night&lt;/h1&gt;
&lt;p&gt;For such night shots, we need to leave the shutter open as long as possible. With this camera, there is a cap at 6 seconds, which is more than enough.&lt;/p&gt;
&lt;p&gt;However, taking 6-second-long pictures takes approximatively 45 seconds to be processed by the Raspberry Pi.&lt;/p&gt;
&lt;p&gt;There are multiple parameters that affect the look of a photos but after trying a few and a lot of &lt;a href="https://www.reddit.com/r/raspberry_pi/comments/3r29ix/night_photography_and_the_pi_camera/"&gt;Googling&lt;/a&gt;, here is a set of parameters that work pretty well for me:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="k"&gt;while&lt;/span&gt; true&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
  raspistill -q &lt;span class="m"&gt;100&lt;/span&gt; -t &lt;span class="m"&gt;1&lt;/span&gt; -ss &lt;span class="m"&gt;6000000&lt;/span&gt; -rot &lt;span class="m"&gt;180&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
  -sh &lt;span class="m"&gt;0&lt;/span&gt; -co &lt;span class="m"&gt;50&lt;/span&gt; -br &lt;span class="m"&gt;50&lt;/span&gt; -sa &lt;span class="m"&gt;0&lt;/span&gt; -ev +2 -ex night &lt;span class="se"&gt;\&lt;/span&gt;
  -awb auto -ISO &lt;span class="m"&gt;800&lt;/span&gt; -mm average -n &lt;span class="se"&gt;\&lt;/span&gt;
  -o &lt;span class="s2"&gt;&amp;quot;&lt;/span&gt;&lt;span class="k"&gt;$(&lt;/span&gt;date -u +&lt;span class="s1"&gt;&amp;#39;%Y-%m-%dT%H:%M:%S&amp;#39;&lt;/span&gt;&lt;span class="k"&gt;)&lt;/span&gt;&lt;span class="s2"&gt;.jpg&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; date&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="k"&gt;done&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;This command takes as many shots as possible in a infinite loop, and displays the date and time between two shots in the terminal.&lt;/p&gt;
&lt;p&gt;Here the parameters &lt;code&gt;-awb auto&lt;/code&gt;, &lt;code&gt;-mm average&lt;/code&gt; and &lt;code&gt;-sa 0&lt;/code&gt; seem to have no impact, I believe they are the default values. The rest makes a difference.&lt;/p&gt;
&lt;iframe width="700" height="394" src="https://www.youtube-nocookie.com/embed/ybX9RmXJBX4?rel=0" frameborder="0" allowfullscreen&gt;&lt;/iframe&gt;

&lt;h1 id="live-streaming-on-youtube"&gt;Live streaming on Youtube&lt;/h1&gt;
&lt;p&gt;This is fairly easy and cool to do! Head out to &lt;a href="https://studio.youtube.com/channel/UC/livestreaming"&gt;https://studio.youtube.com/channel/UC/livestreaming&lt;/a&gt; and retrieve a "Stream key".&lt;/p&gt;
&lt;div style="text-align: center"&gt;
&lt;img src="https://romainpellerin.eu/images/raspberry-pi-camera-youtube.png" alt="Youtube UI" /&gt;
&lt;/div&gt;

&lt;p&gt;Then:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;raspivid -o - -rot &lt;span class="m"&gt;180&lt;/span&gt; -t &lt;span class="m"&gt;0&lt;/span&gt; -w &lt;span class="m"&gt;1280&lt;/span&gt; -h &lt;span class="m"&gt;720&lt;/span&gt; -fps &lt;span class="m"&gt;25&lt;/span&gt; -b &lt;span class="m"&gt;4000000&lt;/span&gt; -g &lt;span class="m"&gt;50&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="p"&gt;|&lt;/span&gt; ffmpeg -ar &lt;span class="m"&gt;44100&lt;/span&gt; -ac &lt;span class="m"&gt;2&lt;/span&gt; -f s16le -i /dev/zero -f h264 -i - &lt;span class="se"&gt;\&lt;/span&gt;
  -vcodec copy -acodec aac -ab 128k -g &lt;span class="m"&gt;50&lt;/span&gt; -strict experimental -f flv &lt;span class="se"&gt;\&lt;/span&gt;
  rtmp://a.rtmp.youtube.com/live2/&amp;lt;your-secret-key-here&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;This would create a live stream with no audio. To add an audio track that repeats itself, do:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;raspivid -o - -rot &lt;span class="m"&gt;180&lt;/span&gt; -t &lt;span class="m"&gt;0&lt;/span&gt; -w &lt;span class="m"&gt;1280&lt;/span&gt; -h &lt;span class="m"&gt;720&lt;/span&gt; -fps &lt;span class="m"&gt;25&lt;/span&gt; -b &lt;span class="m"&gt;4000000&lt;/span&gt; -g &lt;span class="m"&gt;50&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="p"&gt;|&lt;/span&gt; ffmpeg -stream_loop -1 -i ./audio.mp3 -f h264 &lt;span class="se"&gt;\&lt;/span&gt;
  -use_wallclock_as_timestamps &lt;span class="m"&gt;1&lt;/span&gt; -thread_queue_size &lt;span class="m"&gt;1024&lt;/span&gt;  -i - &lt;span class="se"&gt;\&lt;/span&gt;
  -map &lt;span class="m"&gt;0&lt;/span&gt;:0 -map &lt;span class="m"&gt;1&lt;/span&gt;:0 -vcodec copy -acodec copy -g &lt;span class="m"&gt;50&lt;/span&gt; -strict experimental -f flv &lt;span class="se"&gt;\&lt;/span&gt;
  rtmp://a.rtmp.youtube.com/live2/&amp;lt;your-secret-key-here&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;&lt;code&gt;-use_wallclock_as_timestamps&lt;/code&gt; makes a warning message about no timestamps disappear. &lt;code&gt;-thread_queue_size 1024&lt;/code&gt; makes another warning message disappear.&lt;/p&gt;
&lt;p&gt;With a height of 720 pixels, close to the full width of the sensor is used. If instead we had used 1920x1080, the image would be slightly cropped.&lt;/p&gt;
&lt;div style="text-align: center"&gt;
&lt;a href="https://picamera.readthedocs.io/en/release-1.12/fov.html" target="_blank"&gt;&lt;img src="https://romainpellerin.eu/images/raspberry-pi-camera-resolutions.png" alt="Supported resolutions" /&gt;&lt;/a&gt;
&lt;/div&gt;

&lt;h1 id="daytime-timelapse"&gt;Daytime timelapse&lt;/h1&gt;
&lt;p&gt;Here, it's pretty much like a nighttime timelapse, except that we don't need as many parameters, the default ones should normally do a decent job. Also, since taking a picture is here much more faster, we must schedule the shots. Every 20 or 30 seconds is usually a safe bet. Since we can't predict with certainty how long taking the picture will take, in order to take timely shots, we must run a script in the background to take the photo and wait x seconds in an infinite loop:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="k"&gt;while&lt;/span&gt; true&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt; ./take-pic.sh&lt;span class="p"&gt;;&lt;/span&gt; sleep &lt;span class="m"&gt;20&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;done&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;And the file &lt;code&gt;./take-pic.sh&lt;/code&gt; (don't forget to &lt;code&gt;chmod +x ./take-pic.sh&lt;/code&gt;):&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="ch"&gt;#!/bin/bash&lt;/span&gt;
&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;Taking pic...&amp;quot;&lt;/span&gt;
&lt;span class="nv"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;&lt;/span&gt;&lt;span class="k"&gt;$(&lt;/span&gt;date -u +&lt;span class="s1"&gt;&amp;#39;%Y-%m-%dT%H:%M:%S&amp;#39;&lt;/span&gt;&lt;span class="k"&gt;)&lt;/span&gt;&lt;span class="s2"&gt;.jpg&amp;quot;&lt;/span&gt;
raspistill -q &lt;span class="m"&gt;100&lt;/span&gt; -rot &lt;span class="m"&gt;180&lt;/span&gt; -n -awb sun -co &lt;span class="m"&gt;20&lt;/span&gt; -o &lt;span class="s2"&gt;&amp;quot;&lt;/span&gt;&lt;span class="nv"&gt;$name&lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;&lt;/span&gt; &lt;span class="p"&gt;&amp;amp;&lt;/span&gt;
date
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;iframe width="700" height="394" src="https://www.youtube-nocookie.com/embed/CxOuNB-NVDQ?rel=0" frameborder="0" allowfullscreen&gt;&lt;/iframe&gt;

&lt;iframe width="700" height="394" src="https://www.youtube-nocookie.com/embed/9GTVajBlVuM?rel=0" frameborder="0" allowfullscreen&gt;&lt;/iframe&gt;

&lt;p&gt;That's it for today!&lt;/p&gt;</content><category term="Computers"></category><category term="raspberry pi"></category></entry><entry><title>On Storing Passwords In A Safe Way</title><link href="https://romainpellerin.eu/on-storing-passwords-in-a-safe-way.html" rel="alternate"></link><published>2018-07-31T00:20:00+02:00</published><updated>2020-01-06T10:48:00+01:00</updated><author><name>Romain Pellerin</name></author><id>tag:romainpellerin.eu,2018-07-31:/on-storing-passwords-in-a-safe-way.html</id><summary type="html">&lt;p&gt;My journey towards increased security&lt;/p&gt;</summary><content type="html">&lt;p&gt;It's been a while since I last wrote here... Let's fix this with a new article on an important topic.&lt;/p&gt;
&lt;h1 id="storing-passwords"&gt;Storing passwords&lt;/h1&gt;
&lt;p&gt;For a very long time I have stored my passwords within Firefox, synced "in the Cloud" through my Firefox account. This solution offers four main advantages:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Passwords are synced accross devices, always at hand&lt;/li&gt;
&lt;li&gt;Passwords are conveniently auto-filled as I browse the web&lt;/li&gt;
&lt;li&gt;Passwords are encrypted on Mozilla's servers (&lt;a href="https://support.mozilla.org/en-US/questions/1169355"&gt;source&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;Passwords are encrypted locally on my computer (&lt;a href="https://support.mozilla.org/en-US/questions/1210914"&gt;source&lt;/a&gt;), although a Master Password is required to prevent theft (since the encryption key is stored in plain) by adding another layer of security (&lt;a href="https://support.mozilla.org/en-US/questions/1041243"&gt;source&lt;/a&gt;)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;While this solution had seemed like a good one for a while, I recently thought I could do better than putting my trust in a company - even though Mozilla is respectable and trustworthy. Eventually, every big company gets hacked and I don't really know how they encrypt my data on their servers.&lt;/p&gt;
&lt;p&gt;Moreover, I wanted to be able to safely backup my passwords somewhere (offline, if need be, or elsewhere). My past solution had a flaw: were I to lose my laptop and smartphone (theft, apartment burns dowm, earthquake, whatever), I'd have no way to recover my passwords since I don't know any of them, not even my Firefox password (what good would it be for anyway, since two factor authentication is enabled and my two only trusted devices would be lost).&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Side note on this topic&lt;/em&gt;: I always randomly type my passwords as I create accounts. I don't use services that generate them for me (like Dashlane or Lastpass to mention a few). I don't trust these programs to store my passwords (we'll see why in a bit). Nonetheless, I always make sure to include capital letters, numbers and special characters, with a length greater than 8.&lt;/p&gt;
&lt;p&gt;With this all in mind, I needed to find a solution that could fulfill the following requirements:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Not hosted on someone else's servers&lt;/li&gt;
&lt;li&gt;Encrypted at all times&lt;/li&gt;
&lt;li&gt;Easily accessible on multiple devices, including Linux and mobile phone(s)&lt;/li&gt;
&lt;li&gt;Synced accross my devices&lt;/li&gt;
&lt;li&gt;As much user friendly as possible so that I can easily switch to this new solution and change my habits&lt;/li&gt;
&lt;li&gt;Backed up offline or in a different location AND easily recoverable in case of loss of my trusted devices&lt;/li&gt;
&lt;li&gt;Based on a non proprietary solution - both free and open source ideally - and free of charge&lt;/li&gt;
&lt;li&gt;Auto form-filling on a web is a plus (through a web extension for instance)&lt;/li&gt;
&lt;li&gt;Two factor auth management is a plus: it could be nice to save 2FA secrets as well&lt;/li&gt;
&lt;li&gt;Password generation is optional, I'm fine with random typing on my keyboard every once in a while&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="market-analysis"&gt;Market analysis&lt;/h2&gt;
&lt;h3 id="1password"&gt;1password&lt;/h3&gt;
&lt;p&gt;Apparently a great tool, I've read a lof of good reviews. Advocated by the famous website &lt;a href="https://haveibeenpwned.com/1Password"&gt;Have I Been Pwned&lt;/a&gt;. However, since this is proprietary software, it is de facto a no-go for me. Plus it's a paid service.&lt;/p&gt;
&lt;h3 id="keepass"&gt;Keepass&lt;/h3&gt;
&lt;p&gt;&lt;a href="https://keepass.info/"&gt;A tool initially made for Windows&lt;/a&gt;.&lt;/p&gt;
&lt;h4 id="pros"&gt;Pros&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;Encryption out of the box&lt;/li&gt;
&lt;li&gt;Free and open source&lt;/li&gt;
&lt;li&gt;Available on Linux through a port&lt;/li&gt;
&lt;li&gt;There's an Android app&lt;/li&gt;
&lt;li&gt;There's a &lt;a href="https://addons.mozilla.org/fr/firefox/addon/keefox/"&gt;Firefox extension&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Auto form filling&lt;/li&gt;
&lt;li&gt;Automatic generation of passwords&lt;/li&gt;
&lt;li&gt;I can easily save a backup file with all my passwords on my personal cloud&lt;/li&gt;
&lt;li&gt;&lt;a href="https://keepass.info/plugins.html#keeotp"&gt;2FA management through a plugin&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://keepass.info/plugins.html#otpkeyprov"&gt;Database can be protected with 2FA through a plugin&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id="cons"&gt;Cons&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;I must trust the binaries or build them myself after reviewing the sources...&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="pass-linux-cli"&gt;Pass (Linux CLI)&lt;/h3&gt;
&lt;p&gt;&lt;a href="https://www.passwordstore.org/"&gt;A tool&lt;/a&gt; &lt;a href="https://wiki.archlinux.org/index.php/Pass"&gt;for Linux&lt;/a&gt; (CLI) based on GPG. Convenient on a laptop, not very much on a mobile phone. However, I tend to trust a CLI tool more than Keepass. One of the reasons I guess is that it's on the official Linux distributions repos.&lt;/p&gt;
&lt;p&gt;In case of phone loss, here is a nice way to restore the code on your phone by generating QR codes from what's stored in pass:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;sudo apt install qrencode
find .password-store/ -type f -iname &lt;span class="s2"&gt;&amp;quot;*.otp.gpg&amp;quot;&lt;/span&gt; -printf &lt;span class="s1"&gt;&amp;#39;%P\n&amp;#39;&lt;/span&gt; &lt;span class="p"&gt;|&lt;/span&gt; sed -n &lt;span class="s1"&gt;&amp;#39;s|\.gpg||p&amp;#39;&lt;/span&gt; &lt;span class="p"&gt;|&lt;/span&gt; &lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="nb"&gt;read&lt;/span&gt; f&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt; pass &lt;span class="s2"&gt;&amp;quot;&lt;/span&gt;&lt;span class="nv"&gt;$f&lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;done&lt;/span&gt; &lt;span class="p"&gt;|&lt;/span&gt; &lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="nb"&gt;read&lt;/span&gt; s&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt; qrencode -o - &lt;span class="s2"&gt;&amp;quot;&lt;/span&gt;&lt;span class="nv"&gt;$s&lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;&lt;/span&gt; &lt;span class="p"&gt;|&lt;/span&gt; display&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;done&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;h4 id="pros_1"&gt;Pros&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;Encryption out of the box with GPG&lt;/li&gt;
&lt;li&gt;Automatic generation of passwords&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.passwordstore.org/#other"&gt;Cross platform&lt;/a&gt;: Linux, Android and Firefox plugin at least&lt;/li&gt;
&lt;li&gt;I can easily save a backup file with all my passwords on my personal cloud&lt;/li&gt;
&lt;li&gt;2FA management (actually Pass can save any arbitraty data, it's essentially made up of encrypted plain text files)&lt;/li&gt;
&lt;li&gt;Super easily backupable (zip the directory, that's all) on my personal cloud&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id="cons_1"&gt;Cons&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;Not very user friendly&lt;/li&gt;
&lt;li&gt;I must trust binaries, specifically the Android app and Firefox binary; the Linux script has all my trust though (yes, &lt;code&gt;pass&lt;/code&gt; is a script)&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="dashlane-and-lastpass"&gt;Dashlane and Lastpass&lt;/h3&gt;
&lt;p&gt;Proprietary software: no go.&lt;/p&gt;
&lt;p&gt;One cool feature Dashlane offers that is worth mentioning though: setting an emergency contact for your important accounts in case of a critical matter. I wish other tools offered the same feature.&lt;/p&gt;
&lt;h3 id="conclusion"&gt;Conclusion&lt;/h3&gt;
&lt;p&gt;Seems like I'll either go with either Keepass or Pass. I'll update this article as I become familiar with either of them.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Update January 2019&lt;/strong&gt;: I've been using &lt;code&gt;pass&lt;/code&gt; for a few months now and am very satisfied so far.&lt;/p&gt;
&lt;h1 id="another-topic-two-factor-authentication"&gt;Another topic: two-factor authentication&lt;/h1&gt;
&lt;p&gt;For this one, I felt that storing my secrets on my phone (Google Authenticatgor to name it) only sounded a little too much like a Single Point of Failure. Should I ever lose access to my phone for any reason, I'd be locked out of services with two factor authentication enabled. Time had come to find a way to save a backup of these secrets.&lt;/p&gt;
&lt;p&gt;To do so, I developed my own solution: &lt;a href="https://github.com/rpellerin/gauth2/"&gt;gauth2&lt;/a&gt;. It is forked from another project (&lt;a href="https://github.com/gbraad/gauth"&gt;gauth&lt;/a&gt;). I improved it and redesigned it a bit. I also added some features.&lt;/p&gt;
&lt;p&gt;How does it work? Well, it is a web app that stores in one's browser (in the &lt;code&gt;LocalStorage&lt;/code&gt;, to be precise) one's secrets and generate One Time Passwords based on these secrets. The secrets can even be encrypted with a password, to prevent someone with access to the browser from stealing the secrets. It also allows secrets to be exported and imported for more convenience. I am very satisfied with it so far. This, on an encrypted laptop, coupled with Google Authenticator, is a pretty solid combination.&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p&gt;Hope this helps. Cheers!&lt;/p&gt;
&lt;h1 id="online-resources"&gt;Online resources&lt;/h1&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.juliaferraioli.com/blog/2018/08/2fa-sms-you/"&gt;2FA, SMS, and you&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://korben.info/authentification-double-facteur-2fa.html"&gt;L’authentification double facteur (2FA), oui mais pas n’importe comment !&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://chown.me/blog/my-recent-journey-with-2FA.html"&gt;My recent journey with 2FA&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://medium.com/@chasinglogic/the-definitive-guide-to-password-store-c337a8f023a1"&gt;The Definitive Guide to password-store&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://medium.com/@davidpiegza/using-pass-in-a-team-1aa7adf36592"&gt;Using pass in a team&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;</content><category term="Computers"></category><category term="password"></category><category term="security"></category></entry><entry><title>Domain Names</title><link href="https://romainpellerin.eu/domain-names.html" rel="alternate"></link><published>2018-03-23T20:00:00+01:00</published><updated>2018-12-06T17:58:00+01:00</updated><author><name>Romain Pellerin</name></author><id>tag:romainpellerin.eu,2018-03-23:/domain-names.html</id><summary type="html">&lt;p&gt;Where to buy domain names&lt;/p&gt;</summary><content type="html">&lt;p&gt;Short article, kind of a bookmark for myself. I usually buy my domain names from OVH but they're far from being cheap. Today, I was told the following three websites offer much cheaper domain names. What's more, they have a greater choice.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="https://porkbun.com/"&gt;porkbun.com&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.namecheap.com/"&gt;www.namecheap.com&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.internetbs.net/"&gt;www.internetbs.net&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://domainr.com/"&gt;domainr.com&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;</content><category term="Computers"></category><category term="dns"></category><category term="domain"></category></entry><entry><title>How To Repair A Laptop Charger</title><link href="https://romainpellerin.eu/how-to-repair-a-laptop-charger.html" rel="alternate"></link><published>2017-05-02T21:50:00+02:00</published><updated>2022-09-24T12:11:00+02:00</updated><author><name>Romain Pellerin</name></author><id>tag:romainpellerin.eu,2017-05-02:/how-to-repair-a-laptop-charger.html</id><summary type="html">&lt;p&gt;How I replaced my defective laptop charger&lt;/p&gt;</summary><content type="html">&lt;p&gt;A few months ago, my laptop charger started to malfunction. It had to be in a certain position to charge the battery and supply power the my laptop. Recently, this had become really annoying. It was getting worse and worse, so bad that sometimes my laptop would shut down abruptly without any kind of warning as the battery was empty.&lt;/p&gt;
&lt;p&gt;Therefore, I decided to replace the defective charger. I searched the Internet, looking for the same charger, with no luck. All I found were cheap chargers selled by some weird Chinese sellers with poor reviews on Ebay and Amazon.&lt;/p&gt;
&lt;p&gt;In the end, since I could not find the right replacement charger with the same connector and the right specifications, I decided to make my own! Here is how.&lt;/p&gt;
&lt;h1 id="how-to-make-your-own-laptop-charger"&gt;How to make your own laptop charger&lt;/h1&gt;
&lt;p&gt;Basically, one can replace a laptop charger with any other one &lt;a href="https://stickystatic.com/tech/laptop-charger"&gt;on three conditions&lt;/a&gt;:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Output voltage has to be the same&lt;/li&gt;
&lt;li&gt;Output amperage has to be either the same or higher than the original charger&lt;/li&gt;
&lt;li&gt;&lt;a href="https://en.wikipedia.org/wiki/Polarity_symbols"&gt;Polarity&lt;/a&gt; has to be the same&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;All I needed was a power brick (AC/DC converter) meeting the above-mentionned requirements and a cord with the same connector. I decided not to reuse the cord from my original charger. Fortunately, my roommate had an old charger with the matching connector, so I decided to go with that one.&lt;/p&gt;
&lt;figure class="center"&gt;
&lt;img src="https://romainpellerin.eu/images/repair-laptop-charger/connectors.jpg" alt="Connectors" /&gt;
&lt;figcaption&gt;My connector (top) and my roommate's one (bottom)&lt;/figcaption&gt;
&lt;/figure&gt;

&lt;p&gt;Here is the replacement charger I bought for $20, with the exact same specs as mine:&lt;/p&gt;
&lt;figure class="center"&gt;
&lt;img src="https://romainpellerin.eu/images/repair-laptop-charger/power-block.jpg" alt="Power brick" /&gt;
&lt;figcaption&gt;My replacement power brick&lt;/figcaption&gt;
&lt;/figure&gt;

&lt;p&gt;So, as I said, I used my roommate's charger cord to get a connector suited for my laptop. I made sure to cut near the block so that the cord remained long enough.&lt;/p&gt;
&lt;figure class="center"&gt;
&lt;img src="https://romainpellerin.eu/images/repair-laptop-charger/cut-cord.jpg" alt="Cutting the cord" /&gt;
&lt;figcaption&gt;Cutting the cord&lt;/figcaption&gt;
&lt;/figure&gt;

&lt;p&gt;Then, I split the end in two to separate the two wires.&lt;/p&gt;
&lt;figure class="center"&gt;
&lt;img src="https://romainpellerin.eu/images/repair-laptop-charger/split-cord1.jpg" alt="Splitting the cord" /&gt;
&lt;figcaption&gt;Splitting the cord&lt;/figcaption&gt;
&lt;/figure&gt;

&lt;p&gt;I identified each wire using a multimeter. Since my laptop expects the center of the barrel plug to be the positive contact and the barrel to be negative, I needed to know that to correctly assemble the two parts of my to-be charger.&lt;/p&gt;
&lt;figure class="center"&gt;
&lt;img src="https://romainpellerin.eu/images/repair-laptop-charger/multimeter1.jpg" alt="Identifying wires" /&gt;
&lt;figcaption&gt;Identifying wires&lt;/figcaption&gt;
&lt;/figure&gt;

&lt;p&gt;I put adhesive tape on the negative one to remember it.&lt;/p&gt;
&lt;figure class="center"&gt;
&lt;img src="https://romainpellerin.eu/images/repair-laptop-charger/split-cord2.jpg" alt="Adhesive tape on negative wire" /&gt;
&lt;figcaption&gt;Adhesive tape on negative wire&lt;/figcaption&gt;
&lt;/figure&gt;

&lt;p&gt;Then, I cut the connector from the new charger I had just bought. Inside the cord, the two wires were of different colors, one was red and the other blue. Using the multimeter and the connector I had just cut, I identified the negative and positive wires.&lt;/p&gt;
&lt;figure class="center"&gt;
&lt;img src="https://romainpellerin.eu/images/repair-laptop-charger/multimeter2.jpg" alt="Identifying wires" /&gt;
&lt;figcaption&gt;Identifying wires&lt;/figcaption&gt;
&lt;/figure&gt;

&lt;p&gt;This way, I figured out the blue wire was connected to the barrel and the red one to the center. Since the charger had the same polarity as mine, I knew that the blue wire was negative. Consequently, that wire had to be connected to the wire with adhesive tape.&lt;/p&gt;
&lt;figure class="center"&gt;
&lt;img src="https://romainpellerin.eu/images/repair-laptop-charger/two-cords.jpg" alt="Both cords ready to be connected" /&gt;
&lt;figcaption&gt;Both cords ready to be connected&lt;/figcaption&gt;
&lt;/figure&gt;

&lt;p&gt;I twisted the wires to connect them and insulated them with electrical tape.&lt;/p&gt;
&lt;figure class="center"&gt;
&lt;img src="https://romainpellerin.eu/images/repair-laptop-charger/connecting1.jpg" alt="Twisting the wires" /&gt;
&lt;figcaption&gt;Twisting the wires&lt;/figcaption&gt;
&lt;/figure&gt;

&lt;figure class="center"&gt;
&lt;img src="https://romainpellerin.eu/images/repair-laptop-charger/connecting2.jpg" alt="Insulating the wires" /&gt;
&lt;figcaption&gt;Insulating the wires&lt;/figcaption&gt;
&lt;/figure&gt;

&lt;figure class="center"&gt;
&lt;img src="https://romainpellerin.eu/images/repair-laptop-charger/connecting3.jpg" alt="Insulating the cord" /&gt;
&lt;figcaption&gt;Insulating the cord&lt;/figcaption&gt;
&lt;/figure&gt;

&lt;p&gt;That's all! Now I have a new functionning charger perfectly suited to my laptop.&lt;/p&gt;</content><category term="Computers"></category><category term="laptop"></category><category term="charger"></category></entry><entry><title>Fonts, Typefaces And The History Of UTF-8</title><link href="https://romainpellerin.eu/fonts-typefaces-and-the-history-of-utf-8.html" rel="alternate"></link><published>2016-02-04T19:00:00+01:00</published><updated>2017-11-12T13:03:00+01:00</updated><author><name>Romain Pellerin</name></author><id>tag:romainpellerin.eu,2016-02-04:/fonts-typefaces-and-the-history-of-utf-8.html</id><summary type="html">&lt;p&gt;Everything about character encodings, fonts and typefaces&lt;/p&gt;</summary><content type="html">&lt;p&gt;First, let's start with the basics. &lt;a href="http://www.fastcodesign.com/3028971/whats-the-difference-between-a-font-and-a-typeface"&gt;&lt;strong&gt;What's the difference between a font and a typeface?&lt;/strong&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Briefly, a fond is what we use whereas a typeface is what we see. But still, it's a bit more complex. I'll sum up the original article right below.&lt;/p&gt;
&lt;p&gt;In the past, analog printing was done using metal letters rolled in ink and pressed down onto a piece of paper: that was the page layout. For a given typeface (for example Garamond), there were thousands of physical metal blocks, each with the character it was meant to represent, in relief (the type face), existing in different size (10 point, 12, etc.) and different weights (bold, light, medium). Basically, a font is just a subset of a typeface. For example, bolded Garamond in 12 point was considered a different font than normal Garamond in 8 point. But nowadays, both terms can be used interchangeably. However, just in case you would need to know, a reminder could be:&lt;/p&gt;
&lt;p&gt;"&lt;em&gt;The difference between a font and a typeface is the same as that between songs and an album. The former makes up the latter.&lt;/em&gt;"&lt;/p&gt;
&lt;hr /&gt;

&lt;p&gt;Truth be told, let's now take a close look at UTF-8... Once again, I'll sum up &lt;a href="https://www.smashingmagazine.com/2012/06/all-about-unicode-utf8-character-sets/"&gt;an article&lt;/a&gt;. But before, just a quick explanation about specific terms (taken from &lt;a href="https://en.wikipedia.org/wiki/Character_encoding#Code_unit"&gt;Wikipedia&lt;/a&gt;):&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;A &lt;strong&gt;character&lt;/strong&gt; is a minimal unit of text that has semantic value.&lt;/li&gt;
&lt;li&gt;A &lt;strong&gt;character set&lt;/strong&gt; is a collection of characters that might be used by multiple languages.
    Example: The Latin character set is used by English and most European languages, though the Greek character set is used only by the Greek language.&lt;/li&gt;
&lt;li&gt;A &lt;strong&gt;coded character set&lt;/strong&gt; is a character set, where each character is assigned with a unique number.&lt;/li&gt;
&lt;li&gt;A &lt;strong&gt;code point&lt;/strong&gt; is a value that can be used in a coded character set. A code point is a 32-bit integer data type, where the lower 21 bits represent a valid code point value and the upper 11 bits are 0.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Now, a story about Unicode and UTF-8...&lt;/p&gt;
&lt;p&gt;In the 1960's, the American Standards Association created a 7-bit encoding called &lt;em&gt;American Standard Code for Information Interchange&lt;/em&gt; (ASCII). Using 7 bits gives 128 possible characters (that was enough for all lower and upper case Latin letters, numerical digits and most punctuation marks; see an &lt;a href="http://www.asciitable.com/"&gt;ASCII table&lt;/a&gt;).&lt;/p&gt;
&lt;p&gt;A few years later, new microprocessors were created, able to process 8 bits at a time. So they used 8 bits (a byte) to store each character, giving 256 possible values, and thus leaving values from 128 to 255 spare.&lt;/p&gt;
&lt;p&gt;Then, in the 80's, Microsoft Windows introduced its own &lt;strong&gt;character set&lt;/strong&gt; (also known as &lt;em&gt;code page&lt;/em&gt;) called &lt;strong&gt;Windows-1251&lt;/strong&gt;, whose goal was to fill in those space characters (for example, 224 represents the Cyrillic letter &lt;strong&gt;a&lt;/strong&gt;). Furthermore, in the 90's, fifteen other 8 bit character sets were created to cover many different alphabets (called &lt;a href="https://en.wikipedia.org/wiki/ISO/IEC_8859"&gt;ISO-8859-1 to ISO-8859-16&lt;/a&gt;; ISO-8859-12 was abandoned). Nowadays, in web pages, if you don't provide the charset used, most web browsers will use a default one, depending on your country of residence (ISO-8859-1 will likely be used for English countries).&lt;/p&gt;
&lt;p&gt;Nevertheless, in the meantime, a &lt;strong&gt;new standard&lt;/strong&gt; called &lt;strong&gt;Unicode&lt;/strong&gt; was proposed. The purpose: to assign a unique number (known as a code point) to every letter in every language, in more than 256 slots. At the moment, we have &lt;a href="http://www.babelstone.co.uk/Unicode/unicode.html"&gt;over 120,000 code points&lt;/a&gt; and Unicode is also considered a character set itself.&lt;/p&gt;
&lt;h1 id="unicode"&gt;Unicode&lt;/h1&gt;
&lt;p&gt;The next few lies were copy-pasted from the original article.&lt;/p&gt;
&lt;p&gt;"&lt;em&gt;The first 128 Unicode code points are the same as ASCII. The range 128-255 contains currency symbols and other common signs and accented characters (aka characters with &lt;a href="https://en.wikipedia.org/wiki/Diacritic"&gt;diacritical marks&lt;/a&gt;), and much of it is borrowed ISO-8859-1. After 256 there are many more accented characters. After 880 it gets into Greek letters, then Cyrillic, Hebrew, Arabic, Indic scripts, and Thai. Chinese, Japanese and Korean start from 11904 with many others in between. This is great – no more ambiguity – each letter is represented by its own unique number.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;[...]&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Note that these Unicode code points are officially written in hexadecimal preceded by U+. So the Unicode code point H is usually written as U+0048 rather than 72 (to convert from hexadecimal to decimal: 4*16+8=72).&lt;/em&gt;"&lt;/p&gt;
&lt;p&gt;Having more than 256 characters makes Unicode unable to fit into 8 bits. It could however perfectly fit into a 32 bit encoding. But &lt;strong&gt;Unicode is just a standard&lt;/strong&gt;, let's now find out which implementation (or character encoding) was designed.&lt;/p&gt;
&lt;p&gt;It's also important to mention that internally, modern web browsers use Unicode. In C or C++ there is a "wide character" (32 bit character called &lt;code&gt;wchar_t&lt;/code&gt;, an extension of C's 8 bit &lt;code&gt;char&lt;/code&gt;).&lt;/p&gt;
&lt;p&gt;So, now, the remaining problems with Unicode are:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;A lot of existing software and protocols send/receive and read/write 8 bit characters&lt;/li&gt;
&lt;li&gt;Using 32 bits to send/store English text would quadruple the amount of bandwidth/space required&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Several attempts were created to solve this problem such as UCS2 and UTF-16 but the winner is UTF-8 (&lt;em&gt;Universal Character Set Transformation Format 8 bit&lt;/em&gt;). &lt;strong&gt;At the moment and since several years, UTF-8 is the preferred character encoding for the Unicode standard.&lt;/strong&gt;&lt;/p&gt;
&lt;h2 id="utf-8"&gt;UTF-8&lt;/h2&gt;
&lt;p&gt;"&lt;em&gt;UTF-8 is a clever. It works a bit like the Shift key on your keyboard. Normally when you press the H on your keyboard a lower case “h” appears on the screen. But if you press Shift first, a capital H will appear.&lt;/em&gt;" (copy-pasted from the original article)&lt;/p&gt;
&lt;p&gt;UTF-8 treats numbers as follows:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;0-127 as ASCII&lt;/li&gt;
&lt;li&gt;128-191 as the &lt;strong&gt;key to be shifted&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;192-247 as &lt;strong&gt;Shift keys&lt;/strong&gt;&lt;ul&gt;
&lt;li&gt;192-223 is a simple shift&lt;/li&gt;
&lt;li&gt;224-239 are like a double shift&lt;/li&gt;
&lt;li&gt;240 and over is a triple shift&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Consequently, to represent a character, you have four different ways (either on one, two, three or four bytes):&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;1 byte: a number from 0 to 127, it will represent an ASCII character&lt;/li&gt;
&lt;li&gt;2 bytes: a sequence of &amp;lt;Shift key from 192 to 223&amp;gt; + &amp;lt;key to be shifted from 128 to 191&amp;gt;&lt;/li&gt;
&lt;li&gt;3 bytes: &amp;lt;224-239&amp;gt; + &amp;lt;128-191&amp;gt; + &amp;lt;128-191&amp;gt;&lt;/li&gt;
&lt;li&gt;4 bytes: &amp;lt;240-&amp;gt; + &amp;lt;128-191&amp;gt; + &amp;lt;128-191&amp;gt; + &amp;lt;128-191&amp;gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;For example, the sequence 191 followed by 224 could never occur. Another example, taken from the original article:&lt;/p&gt;
&lt;p&gt;"&lt;em&gt;For instance, characters 208 and 209 shift you into the Cyrillic range. 208 followed by 175 is character 1071, the Cyrillic Я. &lt;a href="https://en.wikipedia.org/wiki/UTF-8#Examples"&gt;The exact calculation is (208%32)*64 + (175%64) = 1071&lt;/a&gt;.&lt;/em&gt;"&lt;/p&gt;
&lt;p&gt;"&lt;em&gt;UTF-8 is therefore a multi-byte variable-width encoding. Multi-byte because a single character like Я takes more than one byte to specify it. Variable-width because some characters like H take only 1 byte and some up to 4.&lt;/em&gt;"&lt;/p&gt;
&lt;p&gt;That makes UTF-8 backward compatible with ASCII.&lt;/p&gt;
&lt;h2 id="avoid-most-common-problems"&gt;Avoid most common problems&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Be sure to use UTF-8 on every single page of your website(s).&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;meta&lt;/span&gt; &lt;span class="na"&gt;charset&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;UTF-8&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;(best when written on top of the page, for performance concerns)&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Choose your font wisely because "&lt;em&gt;Unicode defines over 110,000 characters&lt;/em&gt;" and "&lt;em&gt;your browser may not have the correct font to display all of them.&lt;/em&gt;"&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;Be careful when dealing with &lt;a href="http://blog.tremend.ro/2006/09/26/mysql-php-and-utf8/"&gt;MySQL to store text&lt;/a&gt; (&lt;a href="http://cahnory.tumblr.com/post/17108999879/utf-8-comment-%C3%A7a-marche"&gt;another article about it in French, also about PHP&lt;/a&gt;)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;That's it about Unicode and UTF-8! Hope it was useful.&lt;/p&gt;
&lt;h1 id="further-reading"&gt;Further reading&lt;/h1&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="http://utf8everywhere.org/"&gt;UTF-8 Everywhere&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://sametmax.com/la-maison-des-horreurs-de-lencoding/"&gt;La maison des horreurs de l’encoding&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://reedbeta.com/blog/programmers-intro-to-unicode/"&gt;A Programmer’s Introduction to Unicode&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://slides.com/benoitaverty/unicode-pour-les-nuls#/"&gt;Unicode pour les nuls&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;</content><category term="Computers"></category><category term="font"></category><category term="typeface"></category><category term="utf8"></category><category term="unicode"></category></entry><entry><title>Understanding The Memory</title><link href="https://romainpellerin.eu/understanding-the-memory.html" rel="alternate"></link><published>2015-06-26T01:11:00+02:00</published><updated>2022-09-24T12:11:00+02:00</updated><author><name>Romain Pellerin</name></author><id>tag:romainpellerin.eu,2015-06-26:/understanding-the-memory.html</id><summary type="html">&lt;p&gt;Understanding how memory works&lt;/p&gt;</summary><content type="html">&lt;p&gt;Understanding memory management can be a bit difficult for beginners. However, it's still one of the most important things every developer should know. You'll need to know how it works to write memory-efficient code, to avoid stack overflows. This is especially true when developing for mobile platforms that have very limited memory. Today's cheapest smartphones have an average of 512MB memory. Android will kill any app that consumes too much memory with even warning you. So be careful beforing allocating too many objects.&lt;/p&gt;
&lt;p&gt;Nows, let's have a look at memory and let's try to understand how it works.&lt;/p&gt;
&lt;h1 id="processes-and-threads"&gt;Processes and threads&lt;/h1&gt;
&lt;p&gt;Basically, when a program is launched, the operating system grants it a certain space in memory. The allocated memory contains &lt;strong&gt;four main areas&lt;/strong&gt;:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Data&lt;/strong&gt;: contains the global and static variables (explicitly initialized with a non-zero or non-NULL value, according to &lt;a href="https://en.wikipedia.org/wiki/Data_segment"&gt;Wikipedia&lt;/a&gt;) used by the program. The content of constants is on the data segment, whereas references to constants are on the code (see next bullet point). The BSS segment (which is usually adjacent to the data segment) contains all global variables and static variables that are initialized to zero or do not have explicit initialization (in such a case, they &lt;a href="http://stackoverflow.com/questions/13251083/the-initialization-of-static-variables-in-c"&gt;are implicitly initialized to 0&lt;/a&gt;). The BSS segment can be considered a part of the data segment.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Code segment&lt;/strong&gt;: contains the assembly code of the program to be executed.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Heap&lt;/strong&gt;: contains all dynamically allocated primitive data types or objects (with &lt;code&gt;malloc&lt;/code&gt; in C or &lt;code&gt;new&lt;/code&gt; in C++, for instance). The developer is in charge of the lifetime of these variables, he has to explicitly deallocate memory (with &lt;code&gt;free&lt;/code&gt; in C or &lt;code&gt;delete&lt;/code&gt; in C++).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Stack&lt;/strong&gt;: it's a LIFO structure. It basically contains all variables being declared inside functions. Every time you enter in a function, a stack frame is created for it. Every time you pass arguments by values to these functions, the arguments are copied to the stack. If you pass references or pointers, their content (an address) is also copied in order to be passed to the function. All the variables on the stack live only inside the function. When the function returns, they are destroyed and the corresponding allocated memory is freed. &lt;strong&gt;Stack values only exist within the scope of the function they are created in.&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;figure class="center"&gt;
&lt;img src="https://romainpellerin.eu/images/memory-stack.jpg" alt="The stack" /&gt;
&lt;figcaption&gt;Image taken from &lt;a href="http://www.linuxjournal.com/article/6391"&gt;http://www.linuxjournal.com/article/6391&lt;/a&gt;&lt;/figcaption&gt;
&lt;/figure&gt;

&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="w"&gt;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;&lt;/span&gt;

&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;&lt;span class="w"&gt;&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="w"&gt;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Let's see how this code gets compiled in x86 assembly.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;gcc -S -masm&lt;span class="o"&gt;=&lt;/span&gt;intel main.c -fno-asynchronous-unwind-tables -o output.asm
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Now, we'll see the instructions using the stack.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;file&lt;/span&gt;&lt;span class="w"&gt;   &lt;/span&gt;&lt;span class="ss"&gt;&amp;quot;main.c&amp;quot;&lt;/span&gt;&lt;span class="w"&gt;&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;intel_syntax&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;noprefix&lt;/span&gt;&lt;span class="w"&gt;&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;text&lt;/span&gt;&lt;span class="w"&gt;&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;globl&lt;/span&gt;&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="k"&gt;add&lt;/span&gt;&lt;span class="w"&gt;&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;type&lt;/span&gt;&lt;span class="w"&gt;   &lt;/span&gt;&lt;span class="k"&gt;add&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;@function&lt;/span&gt;&lt;span class="w"&gt;&lt;/span&gt;
&lt;span class="k"&gt;add&lt;/span&gt;&lt;span class="err"&gt;:&lt;/span&gt;&lt;span class="w"&gt;&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;push&lt;/span&gt;&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;rbp&lt;/span&gt;&lt;span class="w"&gt;&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;mov&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;rbp&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;rsp&lt;/span&gt;&lt;span class="w"&gt;&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;mov&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;DWORD&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;PTR&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="n"&gt;rbp-4&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;edi&lt;/span&gt;&lt;span class="w"&gt;&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;mov&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;DWORD&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;PTR&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="n"&gt;rbp-8&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;esi&lt;/span&gt;&lt;span class="w"&gt;&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;mov&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;edx&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;DWORD&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;PTR&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="n"&gt;rbp-4&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt;&lt;span class="w"&gt;&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;mov&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;eax&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;DWORD&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;PTR&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="n"&gt;rbp-8&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt;&lt;span class="w"&gt;&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="k"&gt;add&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;eax&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;edx&lt;/span&gt;&lt;span class="w"&gt;&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;pop&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;rbp&lt;/span&gt;&lt;span class="w"&gt;&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;ret&lt;/span&gt;&lt;span class="w"&gt;&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;size&lt;/span&gt;&lt;span class="w"&gt;   &lt;/span&gt;&lt;span class="k"&gt;add&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="k"&gt;add&lt;/span&gt;&lt;span class="w"&gt;&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;globl&lt;/span&gt;&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="n"&gt;main&lt;/span&gt;&lt;span class="w"&gt;&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;type&lt;/span&gt;&lt;span class="w"&gt;   &lt;/span&gt;&lt;span class="n"&gt;main&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;@function&lt;/span&gt;&lt;span class="w"&gt;&lt;/span&gt;
&lt;span class="nl"&gt;main&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt;&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;push&lt;/span&gt;&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;rbp&lt;/span&gt;&lt;span class="w"&gt;&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;mov&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;rbp&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;rsp&lt;/span&gt;&lt;span class="w"&gt;&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;sub&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;rsp&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;16&lt;/span&gt;&lt;span class="w"&gt;&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;mov&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;esi&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="w"&gt;&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;mov&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;edi&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="w"&gt;&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="k"&gt;call&lt;/span&gt;&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="k"&gt;add&lt;/span&gt;&lt;span class="w"&gt;&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;mov&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;DWORD&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;PTR&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="n"&gt;rbp-4&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;eax&lt;/span&gt;&lt;span class="w"&gt;&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;mov&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;eax&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="w"&gt;&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;leave&lt;/span&gt;&lt;span class="w"&gt;&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;ret&lt;/span&gt;&lt;span class="w"&gt;&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;size&lt;/span&gt;&lt;span class="w"&gt;   &lt;/span&gt;&lt;span class="n"&gt;main&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;main&lt;/span&gt;&lt;span class="w"&gt;&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ident&lt;/span&gt;&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="ss"&gt;&amp;quot;GCC: (Ubuntu 5.4.0-6ubuntu1~16.04.4) 5.4.0 20160609&amp;quot;&lt;/span&gt;&lt;span class="w"&gt;&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;section&lt;/span&gt;&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;note&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;GNU&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;stack&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="ss"&gt;&amp;quot;&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nv"&gt;@progbits&lt;/span&gt;&lt;span class="w"&gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Threads can be seen as sub-processes, although they belong to a specific process. Thus, they share the same virtual space (same data segment, etc). Only one thing is unique to each thread: they all have their own stack.&lt;/p&gt;
&lt;h1 id="allocating-memory-for-objects-and-primitive-data-types"&gt;Allocating memory for objects and primitive data types&lt;/h1&gt;
&lt;h2 id="c"&gt;C++&lt;/h2&gt;
&lt;p&gt;Every dynamic allocation goes to the heap. The rest on the stack. So every left handside part of the following lines (what is on the left of the equal sign) is on the stack.&lt;/p&gt;
&lt;p&gt;Global variables and static variables (not only global) go to the data segment.&lt;/p&gt;
&lt;p&gt;Here are some examples, to make things clear:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="kt"&gt;void&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nf"&gt;fonction&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;&lt;/span&gt;
&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="n"&gt;Object&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;o&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="c1"&gt;// On the stack&lt;/span&gt;
&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="n"&gt;Object&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;o2&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;Object&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="c1"&gt;// On the stack&lt;/span&gt;
&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="n"&gt;Object&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;ref&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;o&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="c1"&gt;// The reference is on the stack&lt;/span&gt;
&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="n"&gt;Object&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;pt&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;o&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="c1"&gt;// The pointer is on the stack&lt;/span&gt;
&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="n"&gt;Object&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;pt2&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;Object&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="cm"&gt;/* The right handside (the actual object)&lt;/span&gt;
&lt;span class="cm"&gt;    is on the heap, the left handside is on the stack */&lt;/span&gt;&lt;span class="w"&gt;&lt;/span&gt;

&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="cm"&gt;/* Everything that has been allocated on the stack will be&lt;/span&gt;
&lt;span class="cm"&gt;    deleted at the end of the function */&lt;/span&gt;&lt;span class="w"&gt;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;To delete what is on the heap, you need to use the &lt;code&gt;delete&lt;/code&gt; keyword.&lt;/p&gt;
&lt;figure class="center"&gt;
&lt;img alt="Pointers and addresses" src="https://romainpellerin.eu/images/memory_cpp_example.png" /&gt;
&lt;/figure&gt;

&lt;iframe width="700" height="394" src="https://www.youtube-nocookie.com/embed/CSVRA4_xOkw?rel=0" frameborder="0" allowfullscreen&gt;&lt;/iframe&gt;

&lt;h2 id="java"&gt;Java&lt;/h2&gt;
&lt;p&gt;The main difference is that objects on the heap are automatically destroyed by the garbage collector, once they are no longer referenced. Moreover, only primitives are on the stack. All the objects are allocated on the heap. However, references (which are addresses) are passed as arguments to functions on the stack.&lt;/p&gt;
&lt;p&gt;That's all folks!&lt;/p&gt;
&lt;h1 id="further-reading"&gt;Further reading&lt;/h1&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="http://gribblelab.org/CBootcamp/7_Memory_Stack_vs_Heap.html"&gt;7. Memory : Stack vs Heap&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.cplusplus.com/forum/articles/9/"&gt;The difference between pointers and arrays&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://canonical.org/~kragen/memory-models/"&gt;The memory models that underlie programming languages&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://blog.holbertonschool.com/hack-the-virtual-memory-malloc-the-heap-the-program-break/"&gt;Hack the Virtual Memory: malloc, the heap &amp;amp; the program break&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;</content><category term="Computers"></category><category term="code"></category><category term="computer"></category><category term="memory"></category></entry></feed>