Thursday, March 30, 2017

check battery from command line - linux ubuntu

~/learn/battery.upower.markdown.html
 1 
 2 # check battery from command line
 3 
 4 There are at least 2 command you can use,
 5  each will tell the percentage of battery.
 6 
 7     acpi
 8     upower
 9 
10 I made a video to demo it, if needed,
11  you can view the youtube video:
12 [how to get battery status](https://youtu.be/1De5MzqBz7I)
13 
14 By the way, I am using Ubuntu 16.04.
15 
16 ## acpi
17 
18     acpi
19 
20 This is what I got:
21 
22     Battery 0: Charging, 86%, 00:12:32 until charged
23 
24 
25 If you have no acpi installed, use the following to install
26 
27     sudo apt-get install acpi
28 
29 ## upower
30 
31     upower -e
32 
33 or
34 
35     upower --enumerate
36 
37 
38 As example, this is output on my laptop:
39 
40     /org/freedesktop/UPower/devices/line_power_AC
41     /org/freedesktop/UPower/devices/battery_BAT1
42     /org/freedesktop/UPower/devices/DisplayDevice
43 
44 
45 
46 ### Then use one of the above output in the following command
47 
48 
49     upower  -i  /org/freedesktop/UPower/devices/battery_BAT1
50 
51 
52 This is my output this time:
53 
54       native-path:          BAT1
55       vendor:               SANYO
56       model:                45N1767
57       serial:               1097
58       power supply:         yes
59       updated:              Thu 30 Mar 2017 05:00:18 PM CST (62 seconds ago)
60       has history:          yes
61       has statistics:       yes
62       battery
63         present:             yes
64         rechargeable:        yes
65         state:               charging
66         warning-level:       none
67         energy:              24.21 Wh
68         energy-empty:        0 Wh
69         energy-full:         40.09 Wh
70         energy-full-design:  47.52 Wh
71         energy-rate:         28.254 W
72         voltage:             11.753 V
73         time to full:        33.7 minutes
74         percentage:          60%
75         capacity:            84.3645%
76         technology:          lithium-ion
77         icon-name:          'battery-full-charging-symbolic'
78       History (charge):
79         1490864418  60.000  charging
80       History (rate):
81         1490864418  28.254  charging
82 
83 

Tuesday, January 10, 2017

audio recording from usb microphone with linux ubuntu 16, ffmpeg, arecord,

/tmp/ua.md.html
  1 
  2 
  3 
  4 # audio recording from usb microphone
  5 
  6 with linux ubuntu 16, ffmpeg, arecord,
  7 
  8 alsamixer, lsusb, audacity
  9 
 10 
 11 
 12 ref:
 13 
 14     https://trac.ffmpeg.org/wiki/Capture/ALSA
 15 
 16     http://tuxradar.com/content/how-it-works-linux-audio-explained
 17 
 18     http://trac.edgewall.org/
 19 
 20 
 21 ## ALSA, OSS
 22 
 23 On Linux, recording with a USB microphone is best done under ALSA
 24  (Advanced Linux Sound Architecture). Current Audacity provides native
 25  ALSA support. 1.2.x versions of Audacity only support the older OSS
 26  (Open Sound System), but can work with ALSA using an OSS emulation
 27  layer.
 28 
 29 
 30 ## capturing from ALSA
 31 
 32 Capturing audio with ffmpeg and ALSA is pretty much straightforward:
 33 
 34     ffmpeg -f alsa <input_options> -i <input_device> ... output.wav
 35 
 36     -f fmt (input/output)
 37 
 38         Force input or output file format. The format is normally auto
 39         detected for input files and guessed from the file extension
 40         for output files, so this option is not needed in most cases.
 41 
 42     -i url (input), input file url
 43 
 44 
 45 ## Selecting the input card
 46 
 47     input_device tells ffmpeg which audio capturing card or device you
 48     would like to use. To get the list of all installed cards on your
 49     machine, you can type arecord -l or arecord -L (longer output).
 50 
 51 To list recording cards or devices:
 52 
 53     $ arecord -l
 54 
 55         **** List of CAPTURE Hardware Devices ****
 56         card 0: ICH5 [Intel ICH5], device 0: Intel ICH [Intel ICH5]
 57         Subdevices: 1/1
 58         Subdevice #0: subdevice #0
 59         card 0: ICH5 [Intel ICH5], device 1: Intel ICH - MIC ADC [Intel
 60         ICH5 - MIC ADC]
 61         Subdevices: 1/1
 62         Subdevice #0: subdevice #0
 63 
 64 We can see there are 2 audio cards installed that
 65 provide capturing capabilities, namely "card 0"
 66 (Intel ICH5) and "card 1" (Microphone on the USB
 67 web cam). The easiest thing to do is to reference
 68 each of them directly using
 69 
 70     -f alsa -i hw:0
 71 
 72     #@or
 73 
 74     -f alsa -i hw:1:
 75 
 76 
 77     ffmpeg -f alsa -i hw:1 -t 30 out.wav
 78 
 79     That will give us a 30 seconds WAV audio output,
 80     recorded from our USB camera's default recording
 81     device (microphone). The default recording device
 82     can be selected using the alsamixer tool (see
 83     below) or specifying the device using an
 84     additional parameter Y in hw:<X>,<Y>, where
 85     <X>=card, <Y>=device. For example, to select "MIC2
 86     ADC" from Intel card (look above at the list), we
 87     would use:
 88 
 89     ffmpeg -f alsa -i hw:0,2 -t 30 out.wav
 90 
 91 The best way is to select your card and default
 92 recording device with the alsamixer tool, because
 93 some audio cards have a complicated way of
 94 selecting the default input through the ffmpeg
 95 command line.
 96 
 97 
 98 ## Input options
 99 
100 The only useful audio input options for ALSA input are -ar (audio sample rate)
101 and -ac (audio channels).
102 
103 Specifying audio sampling rate/frequency will force the audio card to record
104 the audio at that specified rate. Usually the default value is "44100" (Hz).
105 Specifying audio channels will force the audio card to record the audio as
106 mono, stereo or even 2.1/5.1 (if supported by your audio card). Usually the
107 default value is "1" (mono) for Mic input and "2" (stereo) for Line-In input.
108 
109 
110 Another option for ffmpeg:
111 
112     -thread_queue_size 512
113 
114 
115 ## Example
116 
117 Record audio from the microphone
118 
119 
120     ffmpeg -f alsa -ac 1 -ar 44100 -i hw:0 -t 30 out.wav
121 
122     ffmpeg -thread_queuq_size 512 \
123         -f alsa \
124         -ac 1 \
125         -ar 44100 \
126         -i hw:0 \
127         -t 30 \
128         youFileName.wav
129 
130 
131 
132 
133 ## end of part 1
134 
135 <!-- vim: set tw=70 ft=markdown nowrap fdm=marker ignorecase: -->

Tuesday, December 29, 2015

add a existing user to existing group


usermod, id, Command Line, Linux Ubuntu, 2015 1229


To add an existing user jerry to ftp supplementary/secondary group with usermod command using -a option ~ i.e. add the user to the supplemental group(s). Use only with -G option:
 
  usermod -a -G ftp jerry
  id jerry
 
To change existing jerry's primary group to www, enter:
 
  usermod -g www jerry 
 
 

Friday, December 18, 2015

byte value



# Value of your codes

How much your software codes value?

There are lot's of free codes to use. Should we think it's value as "0",
because it's free so it's zero?

Let's see, a gentleman share his food to others, it's his kindness and the
food is free.  But the food actually keep it's value, it isn't down to "0".

The same should be kept to software codes.  Even we pay nothing to use it, it
should has it's own value.

Codes has value.  How to calculate the value?

First, We need keep away from the concept of market prices, price in market
means buyer is obliged to pay the amount in currency.  We value codes in
senses of how much labor we put in, and how much benefits we get from it.
When we think value this way, it remind us to respect those who contribute to
make us get more codes.

Then we can try to write small price tags for codes, same as we are used to
see in marketplaces.   This is a little bit controversial because we are
trying to write price tag when we aren't in marketplace.

Now, it's time to talk how much, we need number it.


# One byte ten cents

How about 10 cents each byte?  it's one tenth of an US dollar.

One byte ten cents.  Count all bytes includes comments, empty spaces, anything
you typed in.  But be honestly count only your own words, not others.

Why not to count lines of codes (LOC)?  LOC is widely used.  But because we
can read the size of file more easier than count lines, so we can save trouble
from counting lines by reading the size in bytes.

The byte means a byte in ASCII codec, for example "a" is a byte, it's actually
8 bits.  Byte is a natural unit in computer storage.  Nowdays, we use UTF-8
encoding more often, it turns out to be compatible to ASCII encoding.  Beside
English, UTF-8 supports nearly all human languages.

When talk about value, there are more ways to count the value, for example,
count it as hours of labor, man monthes, or instead just keep using LOC.  And
value is not only produced by code-writters, actually, more value is
contributed by those not programmers, such as organizers, designers,
reviewers, other supporters and more.  Count them all if needed.


# Put it in a JSON file

After we get value, write a json file as follow:

    {
        "value":     22.00,
        "who":       "My-name-is-gg-cat",
        "what":      "a few php files set up a blog",
        "when":      "2015 11-23 19:18",

        "and":       "all the rest are optional :)",
        "key":       "value of key",
        "attribute": "value of the attribute",

        "description":   ".....",
        "for-what":      "a file (foo.c) doing some hello world print demo in project"

        "currency":      "USD",
        "more-things":   "more is you want",
        "more":          "... ..."
    }


Using JSON file will make things simple for programmers who has already know
it.  It's kind of standart data structure, easy to learn and easy to use.  It
can be processed by almost all programming languages.  Put a single json
object in the file closed by a pair of "{}", it can describe the value of
codes.

The first 3 attributes is mandatary: value, who (user-id), what and when, the
unit of the value defaults to US dollar.  All the rest keys, values are
optional, it give chances to make thing more clear if you add more attributes.

Then upload the json file to user "jobs", he will do the file keeping things.

At last we value codes, use json file to save data of value.  But thing will
not stop, it always moving forward.  Value is going to change, it keep
changing all the time.  Even price of gold changes in market, in history,
value can not be fix to a number.  And keep in mind that, when we talk about
code's value, we need to know huge part of value come from those who are not
programmer. 


# Conclusions

We try to set up a simple approach to measure value of software codes, this
should be helpful to improve software projects.  The picture can be broad and
deep when there're actually many roles and labors involved.  Still we want
keep it simple:

    1, measure value data
    2, write json file and upload it

We tried to make it easy to claim value, at least in our system. But,
there is no attempt to make the process accurate or make it close to
marketplace exchangeable.


<!--
vim: set ft=markdown tw=78:
-->