Difference between revisions of "Linux"
(14 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
{{:pi}} | |||
==unix== | ==unix== | ||
http://www.namhuy.net/3116/how-to-fix-gpg-error-no_pubkey-in-ubuntu.html | |||
===commands=== | ===commands=== | ||
chmod -R 777 /var/backups/dog | chmod -R 777 /var/backups/dog | ||
sudo chown -R tim www | |||
du -ah /var/www //gives size of directory and everything in it | du -ah /var/www //gives size of directory and everything in it | ||
vim . //opens vim with directory tree | vim . //opens vim with directory tree | ||
rename_a_file mv oldname newname | |||
landscape-sysinfo | |||
grep -r "siteUrlis dog" /var/www/fworks/meteor/epool //search for text recursively | |||
sudo ps -x | grep meteor | |||
sudo kill -s KILL 29484 | |||
df list filesystem | |||
sudo halt -p shuts down power | |||
sudo ifconfig find ip adress etho innet addr is lan ip (ipconfig on windoows) | |||
====locate==== | |||
sudo apt-get updat | |||
sudo apt-get install mlocate | |||
sudo updatedb | |||
locate libtinfo.so.5 | |||
{{:e2fsck}} | |||
{{:address already in use}} | |||
{{:home ubuntu}} | |||
==tools== | |||
===perl=== | ===perl=== | ||
*[http://download.boulder.ibm.com/ibmdl/pub/software/dw/library/l-p102/tomc.txt one liners] | *[http://download.boulder.ibm.com/ibmdl/pub/software/dw/library/l-p102/tomc.txt one liners] |
Latest revision as of 18:13, 18 September 2015
pi
- back to pi and pine
keep shit in c://iot/pi user ubuntu paswd Pinj
in winscp new sessions window edit advanced advanced shell shell sudo-s from dropdown
http://yannickloriot.com/2016/04/install-mongodb-and-node-js-on-a-raspberry-pi/
installed node with the 16.04 instructions using nvm
http://raspberrypi.stackexchange.com/questions/48056/login-as-root-not-possible
systemctl start mongodb systemctl enable mongodb
getting started
- get sd formatter https://www.sdcard.org/downloads/formatter_4/eula_windows/index.html
- get noobs https://www.raspberrypi.org/downloads/noobs/
- run sdformatter
- unzip noobs and load files on sdcard
connect keyboard and monitor and internet and power up the pi and install raspbian
setting up python
sudo apt-get update sudo apt-get python-pip sudo apt-get install python-dev sudo pip install virtualenv
create a project directory
cd projdir virtualenv venv
running in a virtualenv doesn't work because pi doesn't have access to /dev/mem which is used by GPIO
so all the following commmands need sudo
install flask
pip install Flask
install gevent
pip install gevent pip install RPi.GPIO pip install -U flask-cors
sudo python cascada2.py
default
user pi passwd raspberry
current
pi@10.0.1.155 ranj..
login loop
-bash: error while loading shared libraries: libtinfo.so.5: cannot open shared object file or directory
http://raspberrypi.stackexchange.com/questions/36467/how-to-repair-login-loop-bash-error
https://www.raspberrypi.org/forums/viewtopic.php?uid=159601&f=28&t=120846&start=0
https://www.raspberrypi.org/forums/ucp.php
bluetooth 4.0 LE
http://www.ioncannon.net/linux/1570/bluetooth-4-0-le-on-raspberry-pi-with-bluez-5-x/
http://www.elinux.org/RPi_Bluetooth_LE
python
jupyter on python3
is installed in omen www/environments/jup
tim@omen:/d/fs/www/environments$ pyvenv jup tim@omen:/d/fs/www$ cd environments/ tim@omen:/d/fs/www/environments$ . jup/bin/activate (jup) tim@omen:/d/fs/www/environments$ jupyter notebook (jup) tim@omen:/d/fs/www/environments/jup/bin$ deactivate
accessing object properties
status ={} status['pond'] = {'spot': 'center', 'state': 'off', 'tleft': 0, 'nexton': 9}
status['pond']['tleft']= 16
parsing u'5'
basic tutorial
running app forever - supervisorctl
cascada
- port = 8087
- /home/pi/mypi/cascada/server/cascada.py
cascada2
- port = 8088
- /home/pi/mypi/cascada/server/cascada2.py
<markdown>
sudo`supervisorctl` reads configuration from `/etc/supervisor/conf.d` and runs whatever files if finds there.
a typical `conf` ile looks like:
[program:cascada2] command=/usr/bin/python /home/pi/mypi/cascada/server/cascada2.py directory=/home/pi/mypi/cascada/server autostart=true autorestart=true startretries=3 stderr_logfile=/var/log/cascada/cascada2.err.log stdout_logfile=/var/log/cascada/cascada2.out.log user=root environment=SECRET_PASSPHRASE='this is secret',SECRET_TWO='another secret'
you may have to `>supervisor reload` then `ctrl c` the `sudo supervisorctl` to get a new program running forever
</markdown>
pi@raspberrypi ~ $ sudo supervisorctl cascada RUNNING pid 2273, uptime 7 days, 3:17:36
tail -f /var/log/cascada/cascada.out.log tail -f /var/log/cascada/cascada.err.log
after changing cascada.py
pi@raspberrypi ~ $ sudo supervisorctl cascada RUNNING pid 2273, uptime 7 days, 3:17:36 supervisor> stop cascada
exit w ctrl C
sudo lsof -i :8087 sudo kill -9 21118 (kill whatever port lsof returns)
pi@raspberrypi ~ $ sudo supervisorctl cascada STOPPED Jul 16 04:34 PM supervisor> start cascada cascada: started supervisor>
exit w ctrl C ??
- nohup python app.py &
- use screen
- run supervisord(link) on system startup and control all through it (pythonic way :))
nohup means: do not terminate this process even when the stty is cut off.
& at the end means: run this command as a background task.
SSE - Server Side Events
http://flask.pocoo.org/snippets/116/
https://github.com/stevenewey/ssedemo
for node
https://www.npmjs.com/package/simple-sse (has room,haven't tried)
https://tomkersten.com/articles/server-sent-events-with-node/
http://www.futureinsights.com/home/real-time-the-easy-way-with-eventsource-angularjs-and-nodejs.html
SocketIO
http://stackoverflow.com/questions/17641602/how-to-emit-to-room-in-socket-io
flask socketio
https://flask-socketio.readthedocs.org/en/latest/
ibeacon
http://www.jaredwolff.com/blog/get-started-with-bluetooth-low-energy/ decribes gattr tool as well
xyfindit
00:eb:19:00:b7:b9,07775dd0111b11e491910800200c9a66,6400,47033,-59,-68
android
https://github.com/alt236/Bluetooth-LE-Library---Android
distance
http://stackoverflow.com/questions/20416218/understanding-ibeacon-distancing
http://en.wikipedia.org/wiki/DBm
The iBeacon output power is measured (calibrated) at a distance of 1 meter. Let's suppose that this is -59 dBm (just an example). The iBeacon will include this number as part of its LE advertisment.
The listening device (iPhone, etc), will measure the RSSI of the device. Let's suppose, for example, that this is, say, -72 dBm.
Since these numbers are in dBm, the ratio of the power is actually the difference in dB. So:
ratio_dB = txCalibratedPower - RSSI To convert that into a linear ratio, we use the standard formula for dB:
ratio_linear = 10 ^ (ratio_dB / 10) If we assume conservation of energy, then the signal strength must fall off as 1/r^2. So:
power = power_at_1_meter / r^2. Solving for r, we get:
r = sqrt(ratio_linear) In Javascript, the code would look like this:
function getRange(txCalibratedPower, rssi) {
var ratio_db = txCalibratedPower - rssi; var ratio_linear = Math.pow(10, ratio_db / 10);
var r = Math.sqrt(ratio_linear); return r;
} Note, that, if you're inside a steel building, then perhaps there will be internal reflections that make the signal decay slower than 1/r^2. If the signal passes through a human body (water) then the signal will be attenuated. It's very likely that the antenna doesn't have equal gain in all directions. Metal objects in the room may create strange interference patterns. Etc, etc... YMMV.
shareeditflag edited Feb 7 '14 at 2:19
answered Feb 7 '14 at 1:24
Mark Fassler 43135
http://stackoverflow.com/questions/15687332/bluetooth-le-rssi-for-proximity-detection-ios
estimote
Hi Wojtek,
Yep I got them and they are an exciting technology. But I must live in a 2.4 ghz jungle. That and the interesting variability you get between dog lying down, standing up and walking around can alter their signal markedly. Add to that the changes to the signal as I move about the house with my phone and you have a real puzzle.
I have better luck fixing by fixing my bluetooth receiver(s) and not detecting the beacons from mobile devices.
So I have set up raspberry pi's at key points in the yard to track the beacons. Using the libraries Bluez and Bluepy. I am able to estimate distance using the dB difference between the RSSI and the dB at 1 meter to get a power ratio that varies with the square of the distance. It is still cranky but once I put a few pi's in the yard I'll have boatloads of data to play around with.
It will be interesting to try out some filters, maybe put the data through a Hidden Markov Model or train up a neural network.
I have got some other beacons from other manufacturers and they all have similar variability. What would keep my concentration on Estimotes would be a bit of information on the Unknown Services that show up on scans. In particular, you advertise your beacons as standing out with capabilities like the accelerometer on board. How do I read that?
Meanwhile, the pi's are running a little restful API and some socket.io to communicate with my mobile devices and laptops. I'll have a mobile friendly responsive design HTML5/javascript app running soon. If I was doing dedicated I'd start on Android before IOS.
Thanks for your offer of help. Good luck with your product. The potential is enormous.
unix
http://www.namhuy.net/3116/how-to-fix-gpg-error-no_pubkey-in-ubuntu.html
commands
chmod -R 777 /var/backups/dog sudo chown -R tim www du -ah /var/www //gives size of directory and everything in it vim . //opens vim with directory tree rename_a_file mv oldname newname landscape-sysinfo grep -r "siteUrlis dog" /var/www/fworks/meteor/epool //search for text recursively sudo ps -x | grep meteor sudo kill -s KILL 29484 df list filesystem sudo halt -p shuts down power sudo ifconfig find ip adress etho innet addr is lan ip (ipconfig on windoows)
locate
sudo apt-get updat sudo apt-get install mlocate sudo updatedb locate libtinfo.so.5
e2fsck
finding port of address already in use
$ sudo netstat -nlp | grep 80 tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 125004/nginx
or
# sudo lsof -i :25 COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME exim4 2799 Debian-exim 3u IPv4 6645 0t0 TCP localhost:smtp (LISTEN) exim4 2799 Debian-exim 4u IPv6 6646 0t0 TCP localhost:smtp (LISTEN)
home ubuntu
Ubuntu 12.04LTS
sudo halt -p
/etc/network/interfaces to make 10.0.1.101 static
# This file describes the network interfaces available on your system # and how to activate them. For more information, see interfaces(5). # The loopback network interface auto lo iface lo inet loopback # The primary network interface auto eth0 iface eth0 inet static address 10.0.1.101 netmask 255.255.255.0 gateway 10.0.1.1 dns-nameservers 8.8.8.8 10.0.1.1
- lamp
- https://www.digitalocean.com/community/articles/how-to-install-linux-apache-mysql-php-lamp-stack-on-ubuntu
- http://10.0.1.101/info.php
- ruby1.9.3 rails4.0.0
- https://www.digitalocean.com/community/articles/how-to-install-ruby-on-rails-on-ubuntu-12-04-lts-precise-pangolin-with-rvm
tools
perl
handy code
remove blank lines from file
perl -wnl -e 'print $_ unless /^$/' infile.txt >outfile.txt
sed awk
- SED tutorial
- http://tech.bluesmoon.info/2008/09/programming-patterns-in-sed.html
- http://www.vectorsite.net/tsawk_2.html
- lib/images/toolbar/list_ul.png
- lib/images/toolbar/rule.png
- lib/tpl/default/images/interwiki.png
People with shell access to their server can copy the text above and paste it into a file on the system, then run the following commands to check for and remove all those files. Only those that exist are removed.
grep -Ev "^($|#)" /tmp/removeold.txt | xargs -n 1 rm -f
If you are paranoid, replace the "rm -f" with "ls -la" to see what files will be deleted.
To remove directories as well as files you have to use:
grep -Ev "^($|#)" /tmp/removeold.txt | xargs -n 1 rm -fd
However, some systems may not support the "rm -d" option for directory removal. In that case, you have to use recursive removal (just be sure to double-check that the file list does not include any paths that will delete too much):
grep -Ev "^($|#)" /tmp/removeold.txt | xargs -n 1 rm -fr
regex
https://alligator.io/js/regular-expressions-for-regular-people/
http://exploringjs.com/impatient-js/ch_regular-expressions.html
https://www.smashingmagazine.com/2019/02/regexp-features-regular-expressions/
php example
$search = array( '@<script[^>]*?>.*?</script>@si', // Strip out javascript '@<[\/\!]*?[^<>]*?>@si', // Strip out HTML tags '@<style[^>]*?>.*?</style>@siU', // Strip style tags properly '@<![\s\S]*?--[ \t\n\r]*>@' // Strip multi-line comments );
$output = preg_replace($search, , $input); return $output; }
?> <?php function sanitize($input) {
if (is_array($input)) { foreach($input as $var=>$val) { $output[$var] = sanitize($val); } } else { if (get_magic_quotes_gpc()) { $input = stripslashes($input); } $input = cleanInput($input); $output = mysql_real_escape_string($input); } return $output;
}
typical
A username fro 3- 16 characters w -or_ /^[a-z0-9_-]{3,16}$/
a password 6-18 long /^[a-z0-9_-]{6,18}$/
a hex number /^#?([a-f0-9]{6}|[a-f0-9]{3})$/
- a number sign is optional because it is followed a question mark but if there takes it(greedy)
- 6 characters or 3 character
a slug /^[a-z0-9-]+$/
- beginning of the string (^), followed by one or more (the plus sign) letters, numbers, or hyphens. and the end of the string ($).
an email /^([a-z0-9_\.-]+)@([\da-z\.-]+)\.([a-z\.]{2,6})$/
- . get delimited \.
- each section in parens
only lower case, nubers or dots'/[^a-z0-9.]/'
url /^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$/
- s? s if you got em
- delimit / and . with \
- you don't need http at all (https?:\/\/)? but be greedy
- \d is any number
- ([\da-z\.-]+) numbers letters dotts or hyphens
- \.([a-z\.]{2,6})~ .com .co .commie
- ([\/\w \.-]*)*\/?$/ files and directories
- ([\/\w \.-]*) * is zero or more, \w is words
html tag /^<([a-z]+)([^<]+)*(?:>(.*)<\/\1>|\s+\/>)$/
- .* any characters
- ([^<]+) any characters but a <
- (?:>(.*)<\/\1>|\s+\/>) non-capture group.it will contain either a greater than sign, some content, and a closing tag; or some spaces, a forward slash, and a greater than sign \1 represents the content that was captured in the first capturing group
no dots: ^[^\.]*$
^ - beginning of string [^\.]* - any character except ., any number of repetitions $ - end of string
replace spaces and punctuation with nothing str.replace(/\W/g, )
- \W not letters digits or underscores
to take out all non alpha characters (Ruby)
test_str = "Madam, I'm Adam" str = test_str.gsub(/[^a-zA-Z]/,'') puts str returns MadamImAdam
- ^[ \t]+ //finds all the space and tabs
- [1-9]\. //finds all the line numbers. (replace with #)
- [A-E]\. //find A. etc (replace with ##)
to clean special characters from a string
$clean = preg_replace("/^[^a-z0-9]?(.*?)[^a-z0-9]?$/i", "$1", $text);
sites
- http://rubular.com
- http://e-texteditor.com/blog/2010/beyond-vi
- http://www.grymoire.com/Unix/Regular.html#uh-2
- http://www.regular-expressions.info/php.html
- http://www.bluebox.net/about/blog/2013/02/using-regular-expressions-in-ruby-part-1-of-3/
expressions
If you want to get'Aloha World'out
Input:
RegEx:
\<div\sclass\=\"somename\"\>(?<Text>.*?)\<\/div\>
Yields:
Aloha World (note: In a single group named Text)