Symfony and Doctrine ORM – Many to many bidirectional relation

The classes below illustrate a many to many bidirectional relation with Doctrine ORM, Symfony3 and FOSUserBundle.

Entity User

<?php
// src/AppBundle/Entity/User.php

namespace AppBundle\Entity;

use FOS\UserBundle\Model\User as BaseUser;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;

/**
 * @ORM\Entity
 * @ORM\Table(name="fos_user")
 */
class User extends BaseUser
{
    /**
     * @ORM\Id
     * @ORM\Column(type="integer")
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    protected $id;

    /**
     * @ORM\ManyToMany(targetEntity="UserGroup", inversedBy="users")
     * @ORM\JoinColumn(name="usergroup_id", referencedColumnName="id")
     */
    private $usergroups;

    public function __construct()
    {
        parent::__construct();
        $this->usergroups = new ArrayCollection();
    }
}

Read more “Symfony and Doctrine ORM – Many to many bidirectional relation”

Intel NUC D34010WYK – Accessing and updating the BIOS

For some reason my USB3 external HD wasn’t being recognized by my NUC. I had a very old BIOS version, so I tried updating it, which solved the problem. Here’s how:

Search for the latest bios:
https://downloadcenter.intel.com/search?keyword=D34010WYK

In my case, it was this one. Download and save the .bio file in an USB key.
https://downloadcenter.intel.com/download/26632/NUCs-BIOS-Update-WYLPT10H-86A-

Open your NUC and look for the BIOS security jumper:


Read more “Intel NUC D34010WYK – Accessing and updating the BIOS”

dthUSART – C library for AVR microcontrollers (beta) and example code

I decided to create a simple C library for USART and AVR microcontrollers for the purpose of studying the USART serial interface.

This library is likely to be often updated. Open source code on my github:
https://github.com/xdth/AVR_dthUSART

Below is an example application. It will echo back strings received via serial at 9600 bit rate (defined in dthUSART.h), using the internal oscillator at 1 Mhz.
Read more “dthUSART – C library for AVR microcontrollers (beta) and example code”

Interfacing attiny2313 AVR with HD44780 LCD

We will use an attiny2313 AVR microcontroller to display strings on an HD44780 LCD (4-bit mode).

482 bytes of flash written. Using internal oscillator.

## Connections

+-----------------------------------+----------------+
|            HD44780 LCD            | attiny2313 MCU |
+-----------------------------------+----------------+
| PIN 1 (GND)                       |                |
| PIN 2 (+5V)                       |                |
| PIN 3 (contrast/GND)              |                |
| PIN 4 (reg select)                | PIN 2 (PD0)    |
| PIN 5 (R/W)                       | PIN 3 (PD1)    |
| PIN 6 (Enable)                    | PIN 6 (PD2)    |
| PIN 7                             |                |
| PIN 8                             |                |
| PIN 9                             |                |
| PIN 10                            |                |
| PIN 11                            | PIN 12 (PB0)   |
| PIN 12                            | PIN 13 (PB1)   |
| PIN 13                            | PIN 14 (PB2)   |
| PIN 14                            | PIN 15 (PB3)   |
| PIN 15 (220 Omhs resistor to +5V) |                |
| PIN 16 (GND)                      |                |
+-----------------------------------+----------------+

Read more “Interfacing attiny2313 AVR with HD44780 LCD”

Linux LAN domain – BIND9 and Debian

Disclaimer :: the information in this post was altered in order to avoid disclosing the real details of our internal network.

I wanted to change my LAN domain to srv.dth. All devices connected to my network must resolve this domain automatically and certain devices will have their own FQDN, like: printer.srv.dth.


domain:  srv.dth
network: 10.0.0.0
host:    hs.srv.dth       // "home server", machine where the DNS server will run
host IP: 10.0.0.10

devices:
router.srv.dth            // ISP router
router1.srv.dth           // Home network
router2.srv.dth           // Lab 
hs.srv.dth                // DNS server
printer.srv.dth           // Printer
cam0.srv.dth              // Security cameras
cam1.srv.dth
cam2.srv.dth

Read more “Linux LAN domain – BIND9 and Debian”

Bit Manipulation in C

Bitwise Operators

& AND
| OR
^ XOR
~ NOT

Truth Tables

AND (“&”)

truth table

+--------+--------+-----------------+
| bit a  | bit b  | a & b (a AND b) |
+--------+--------+-----------------+
|     0  |     0  |               0 |
|     0  |     1  |               0 |
|     1  |     0  |               0 |
|     1  |     1  |               1 |
+--------+--------+-----------------+

byte example

     11001000  
   & 10111000 
     -------- 
   = 10001000

Read more “Bit Manipulation in C”

Arduino as ISP

I prefer to develop in pure C instead of using the Arduino framework, for both learning and code size purposes. I use the Arduino board solely as an AVR programmer, using my script qAVR to flash the microcontroller.

## material
– breadboard
– jumper wires
– 10µF capacitor
– 220 ohms resistor
– LED
– Arduino
– Target microcontroller (in our example, attiny2313)

## install dev env
pacman -S avr-gcc avr-libc avrdude
wget https://raw.githubusercontent.com/xdth/qavr/master/qavr (place it in your .bin folder)

Read more “Arduino as ISP”

USB device encrypted LVM on LUKS

Let’s encrypt an external USB hard disk drive. Get root already and type lsblk. Then insert the USB key and check its name by typing lsblk again. In my case, it was sdb1, but yours might be different. Get yours right, or bad things can happen to your other devices.

[root@slayer dth]# lsblk
NAME                    MAJ:MIN RM   SIZE RO TYPE  MOUNTPOINT
...
sdb                       8:16   0   1.8T  0 disk  
└─sdb1                    8:17   0   1.8T  0 part  
...

Read more “USB device encrypted LVM on LUKS”