Skip to content

Instantly share code, notes, and snippets.

@nguyenhien1994
nguyenhien1994 / deboot.sh
Created August 2, 2024 09:58 — forked from knotdevel/deboot.sh
script to build Ubuntu rootfs (for arm64, armhf, powerpc, ppc64el)
#!/bin/bash
#
# deboot.sh
# script to build Ubuntu rootfs (for arm64, armhf, powerpc, ppc64el)
#
# Copyright 2017 knotdevel
# Released under the MIT license
# http://opensource.org/licenses/mit-license.php
#
#
@nguyenhien1994
nguyenhien1994 / svn-rebase.sh
Last active May 3, 2024 06:39 — forked from rhowardiv/svn-rebase.sh
Rebasing in SVN
# First look what happens with a simple but naive approach.
# I'll try recreating the branch in-place and merging in changes from the old version.
# Should be easy, right? svn never forgets, right? ...
cd ~/mybranch
SVH=/repo/root
# (for this approach we need the rev #'s for the start and end of the branch)
START_REV=$(svn log --stop-on-copy | grep '^r[0-9]' | tail -n 1 | sed s/^r// | awk '{print $1}')
END_REV=$(svn log --stop-on-copy | grep '^r[0-9]' | head -n+1 | sed s/^r// | awk '{print $1}')
@nguyenhien1994
nguyenhien1994 / cleaning_robot.md
Created October 17, 2023 01:17
Cleaning robot

There is a cleaning robot which is cleaning a rectangular grid of size Nx M, represented by array R consisting of N strings. Rows are numbered from 0 to N-1 (from top to bottom) and columns are numbered from 0 to M-1 (from left to right).

The robot starts cleaning in the top-left corner, facing rightwards. It moves in a straight line for as long as it can, i.e. while there is an unoccupied grid square ahead of it. When it cannot move forward, it rotates 90 degrees clockwise and tries to move forward again until it encounters another obstacle, and so on. Dots in the array (".") represent empty squares and "X"s represent occupied squares (ones the robot cannot move through). Each square that the robot occupied at least once is considered clean. The robot moves indefinitely.

Write a function: int solution (vector<string> &R); that, given an array R consisting of N strings, each of length M, representing the grid, returns the number of clean squares.

Examples:

@nguyenhien1994
nguyenhien1994 / generate-ssh-key.sh
Created March 23, 2019 15:43 — forked from grenade/01-generate-ed25519-ssh-key.sh
Correct file permissions for ssh keys and config.
ssh-keygen -t rsa -b 4096 -N '' -C "[email protected]" -f ~/.ssh/id_rsa
ssh-keygen -t rsa -b 4096 -N '' -C "[email protected]" -f ~/.ssh/github_rsa
ssh-keygen -t rsa -b 4096 -N '' -C "[email protected]" -f ~/.ssh/mozilla_rsa
@nguyenhien1994
nguyenhien1994 / sendRawEth.c
Created April 18, 2017 11:19 — forked from austinmarton/sendRawEth.c
Send a raw Ethernet frame in Linux
/*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*/
#include <arpa/inet.h>
#include <linux/if_packet.h>
#include <stdio.h>
@nguyenhien1994
nguyenhien1994 / vim.sh
Last active April 18, 2017 08:53
Compiling vim on Ubuntu 16 with LUA-support
# Remove previous installations
sudo apt-get remove vim vim-runtime vim-tiny vim-common
# Install dependencies
sudo apt-get install libncurses5-dev python-dev libperl-dev ruby-dev liblua5.2-dev
# Fix liblua paths
sudo ln -s /usr/include/lua5.2 /usr/include/lua
sudo ln -s /usr/lib/x86_64-linux-gnu/liblua5.2.so /usr/local/lib/liblua.so