March 19, 2016
You can create and mount a ram based disk as follows:
- Create a disk:
$ hdiutil attach -nomount ram://$((2 * 1024 * SIZE_IN_MB))
hdiutil will return the name of the ramdisk.
- Format and mount the disk diskutil eraseVolume HFS+ RAMDisk NAME_OF_DISK Creating a 100MB ramdisk:
$ hdiutil attach -nomount ram://$((2 * 1024 * 100)) /dev/disk3
- Started erase on disk3 Unmounting disk Erasing Initialized /dev/rdisk3 as a 100 MB case-insensitive HFS Plus volume Mounting disk Finished erase on disk3 RAMDisk:
$ diskutil eraseVolume HFS+ RAMDisk /dev/disk3
Source:
linux – Does OS X have an equivalent to /dev/shm? – Stack Overflow
posted in Mac OS X, System Administrator by nico | Comments Off on Does Mac OS X have an equivalent to /dev/shm?
March 17, 2016
The substitute command (
:s
) applies to whole lines, however the
\%V
atom will restrict a pattern so that it matches only inside the visual selection. This works with characterwise and blockwise selection (and is not needed with linewise selection).
For example, put the cursor on this line:
music amuse fuse refuse
In normal mode, type
^wvee
to visually select “amuse fuse” (
^
goes to first nonblank character,
w
moves forward a word,
v
enters visual mode,
e
moves forward to end of next word). Then press Escape and enter the following command to change all “us” to “az” in the last-selected area within the current line:
:s/\%Vus/az/g
The result is:
music amaze faze refuse
Source:
Search and replace in a visual selection – Vim Tips Wiki – Wikia
posted in Linux by nico | Comments Off on VIM: Substituting in a visual selection
February 27, 2016
Problem solved ! Here is a pure sql solution, how to get all sql from all tables in Postgres:
--
--
-- NB 27.02.16
-- List sql tables
-- show_create_table()
--
--
SELECT
'CREATE TABLE '||sql.table||'('
||array_to_string(array_agg(sql),', ')
||')' as sql
FROM (
(
SELECT -- FIELDS
c.oid AS id
,c.relname as table
,9 as prio
,''
|| f.attname
|| ' ' || pg_catalog.format_type(f.atttypid,f.atttypmod)
||CASE WHEN f.attnotnull THEN ' NOT NULL' ELSE '' END
||CASE WHEN f.atthasdef = 't' AND d.adsrc !=''THEN ' DEFAULT '||d.adsrc ELSE '' END
AS sql
FROM pg_attribute f
JOIN pg_class c ON c.oid = f.attrelid
LEFT JOIN pg_attrdef d ON d.adrelid = c.oid AND d.adnum = f.attnum
WHERE c.relkind = 'r'::char
AND f.attnum > 0
ORDER BY f.attnum
) UNION (
SELECT -- CONSTRAINTS
c.oid as id
,c.relname as table
,0 as prio
,CASE
WHEN p.contype = 'p' THEN 'PRIMARY KEY'
WHEN p.contype = 'u' THEN 'UNIQ'
ELSE '' END
||'('||array_to_string(array_agg(f.attname),', ')||')' AS sql
FROM pg_attribute f
JOIN pg_class c ON c.oid = f.attrelid
LEFT JOIN pg_constraint p ON p.conrelid = c.oid AND f.attnum = ANY (p.conkey)
WHERE c.relkind = 'r'::char
AND f.attnum > 0
AND p.contype IN ('u','p')
GROUP BY c.oid,p.contype,f.attrelid,c.relname
ORDER BY c.oid,f.attrelid
)
ORDER BY prio DESC) sql
GROUP BY sql.id,sql.table
;
posted in Database, Postgres by nico | Comments Off on Postgres equivalent show create table
February 2, 2016
If you want to copy or clone packages from one Debian or Ubuntu server to another, here is how to to it:
ssh server1
ssh server2 ‘dpkg –get-selections’| dpkg –set-selections
apt-get -u dselect-upgrade
posted in Divers by nico | Comments Off on Copy / clone packages from servers
August 12, 2015
posted in Electronic by nico | Comments Off on Resistors Colour Codes
August 5, 2015
- Redirect video with VLC:
raspivid -o – -t 99999 -hf -w 400 -h 300 -fps 25|sudo -u nico — cvlc -v – –noaudio –no-sout-audio –sout ‘#standard{access=http,mux=ts,dst=:8090}’ :demux=h264
- Redirect video with netcat:
while true; do raspivid -w 640 -h 480 -fps 25 -t 99999 -o – | nc -l -p 5001; sleep 1 ; done
posted in Linux, Raspberry Pi by nico | Comments Off on Raspberry PI Video
July 30, 2015
Test your disk speed:
fio –randrepeat=1 –ioengine=libaio –direct=1 –gtod_reduce=1 –name=test –filename=test –bs=4k –iodepth=64 –size=4G –readwrite=randrw –rwmixread=75
hdparm -tT /dev/root
posted in System Administrator by nico | Comments Off on Disk speed performance
July 29, 2015
$> telnet localhost smtp
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
220 mailtest ESMTP Postfix (Debian/GNU)
$> ehlo example.com
250-my-new-mailserver
250-PIPELINING
250-SIZE 10240000
250-VRFY
250-ETRN
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN
$> mail from:<nico@example.com>
250 2.1.0 Ok
$> rcpt to:<admin@example.com>
250 2.1.5 Ok
$> data
354 End data with <CR><LF>.<CR><LF>
$> Hi Admin,
$>
$> What's up ?
$> .
250 2.0.0 Ok: queued as A9D64379C4
$> quit
posted in Divers, Linux, System Administrator by nico | Comments Off on SMTP, Send email with telnet
July 29, 2015
Few tips about fail2ban:
- How to delete or free a blocked ip:
fail2ban-client get jail actionunban ipaddress
posted in Linux, System Administrator by nico | Comments Off on Fail2ban secure your server
July 23, 2015
Anoying things about ruby:
- i++ does not work!
- backward version compatibility
- Regexp not as powerfull than perl
- Handling types
posted in Developer by nico | Comments Off on Ruby