Listing posts
Displaying posts 31 - 35 of 328 in total
email validation in rails
Last update
2023-11-24
2023-11-24
« — »
1 2 3 4 | validates :email, presence: true, uniqueness: { case_sensitive: false }, format: { with: URI::MailTo::EMAIL_REGEXP } |
Simply use /\A.+@.+\..+\z/i
and put and end to the overkill.
Source: passwordless gem, railsguides, Stop Validating Email Addresses with Regex
~~~ * ~~~
use github rubygems registry
Last update
2023-11-22
2023-11-22
«free rubygems repository with github
using personal access token»
using personal access token»
Working with the RubyGems registry
generate a personal access token and grant it repo permissions (replace
MY_GITHUB_TOKEN
with its content)cat ~/.gem/credentials
1 2
--- :github: Bearer MY_GITHUB_TOKEN
cat .bundle/config
Note: replace any
-
with___
.1 2
--- BUNDLE_HTTPS://RUBYGEMS__PKG__GITHUB__COM/ACAVALIN/: "acavalin:MY_GITHUB_TOKEN"
cat .gemrc
1 2 3 4 5 6 7 8
gem: --no-document backtrace: false bulk_threshold: 1000 sources: - https://rubygems.org/ - https://acavalin:MY_GITHUB_TOKEN@rubygems.pkg.github.com/acavalin/ update_sources: true verbose: true
build the gem, examples:
gem build name.gemspec
rake --tasks ; rake build
push gem to registry
1
gem push --key github --host https://rubygems.pkg.github.com/acavalin name-0.0.1.gem
use gem in project
- Gemfile:
gem "name "0.0.1", source: "https://rubygems.pkg.github.com/acavalin"
- cmdline:
gem install --clear-sources --source https://acavalin:MY_GITHUB_TOKEN@rubygems.pkg.github.com/acavalin deluge-rpc
- Gemfile:
~~~ * ~~~
~~~ * ~~~
UFW firewall setup
Last update
2023-11-20
2023-11-20
« — »
If you are using it on a VPS then you have to enable iptables NAT beforehand.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | apt-get install ufw # disable IPv6 rules sed -r -i 's/IPV6=yes/IPV6=no/' /etc/default/ufw # write rules in /lib/ufw/user.rules ufw reset # reset to defaults # set our defaults ufw default allow outgoing ufw default deny incoming ufw allow 22/tcp comment ssh ufw allow 80/tcp comment http ufw allow 443/tcp comment https ufw allow 1194/udp comment openvpn ufw allow 1100:1200/tcp # port range (proto required23) ufw allow 53 # allow both tcp and udp (eg: DNS) ufw allow from 1.2.3.4 # single host ufw allow from 192.168.1.0/24 # subnet ufw allow from 1.2.3.4 to any port 22 proto tcp # block an IP if it has attempted to initiate 6 or more # connections in the last 30 seconds ufw limit 22/tcp # show rules added before enabling firewall ufw show added # remove/insert rule ufw status numbered ufw delete <row_number> ufw insert <row_number> <new rule> # show rules ufw show added ufw show raw # other reports ufw show builtins ufw show before-rules ufw show user-rules ufw show after-rules ufw show logging-rules # start/stop/status service ufw enable ufw disable ufw status ufw status verbose ufw reload # reload cfg # see logs ufw logging low # off/low/medium/high/full tail -f /var/log/ufw.log # show blocked incoming ports messages from log/dmesg/journalctl dmesg | grep UFW | sed -r 's/.*(IN=[^ ]+).*(PROTO=[^ ]+).*(DPT=[^ ]+) .*/\1 \2 \3/' | sort -u |
Notes:
- The order of rules is critical in ufw/iptables as a packet will match the first rule, subsequent rules are ignored.
- If something is wrong with filtering/logs you can try to purge and reinstall uwf (especially after a distribution upgrade).
See also: Lullabot
~~~ * ~~~
Backup & restore disk/partitions
Last update
2023-11-17
2023-11-17
«squashfs»
1. Partition table
- using
dd
(do not use for GPT):
1 2 3 4 5 | # dump raw ms-dos table/mbr dd if=/dev/sdX of=mbr.bin bs=512 count=1 dd if=/dev/sdX of=mbr_2mb.bin bs=2MB count=1 # paranoia # restore dd if=mbr.bin of=/dev/sdX |
- using
sfdisk
(version > 2.26 for GPT support):
1 2 3 4 5 6 7 8 9 | # dump raw partition table sfdisk -b -O disk /dev/sdX # disk-<device>-<offset>.bak # restore ls disk-*.bak | sed -r 's/(.+)-(0x.+).bak/dd if=\0 of=\/dev\/sdX seek=$((\2)) bs=1 conv=notrunc/' | bash # dump partition table in text format sfdisk -d /dev/sdX > sdcard.ptable # restore sfdisk /dev/sdX < sdcard.ptable |
2. Partition data
You can use FSarchiver or the old school way:
ext*
efficient backup/restore:
1 2 | e2image -ra /dev/sdXY - | pv | 7za a -mx=9 -si sdXY.e2i.7z 7za x -so sdXY.e2i.7z | pv | dd of=/dev/sdXY bs=4K |
or create a squashfs mountable image1:
1 2 3 4 5 6 7 8 9 10 11 | apt install squashfs-tools # backup mkdir tmpdir mksquashfs tmpdir sdXY.squashfs -p "sdXY.img f 444 root root e2image -ra /dev/sdXY -" -comp xz # mount and... mkdir tmpdir mntdir mount sdXY.squashfs tmpdir pv tmpdir/sdXY.img | dd of=/dev/sdXY # ...restore or... mount tmpdir/sdXY.img mntdir # ...inspect |
ntfs
efficient backup/restore:
1 2 | ntfsclone -s -o - /dev/sdXY | pv | 7za a -mx=9 -si sdXY.nc.7z
7za x -so sdXY.nc.7z | pv | ntfsclone -r -O /dev/sdXY -
|
- raw full backup/restore:
1 2 | dd if=/dev/sdXY | pv | 7za a -mx=9 -si sdXY.dd.7z 7za x -so sdXY.dd.7z | pv | dd of=/dev/sdXY bs=4K |
Tips: dd
seek/skip