Sometimes pdf presentations rely on specific fonts, etc which may be unavailable on some computers.
Sometimes, a given pdf is very slow to show up on certain computers.
A solution can be to convert everything to bitmaps. This increases file size but makes rendering straightforward. With a trick that keeps the png format on the resulting pdf, the results are as crisp as in the original
#!/bin/bash
# Convert PDF file to individual pdf files with given resolution (96 DPI)
# without losing definition.
NPAGES=$(pdfinfo $1 | grep Pages | awk '{print $2}')
echo $NPAGES
for i in $(seq $NPAGES); do
echo Processing page $i
echo Generating "__FILE$i".pdf
pdftk A=$1 cat "A$i" output - | convert -density 96 - png:- | img2pdf -o "__FILE$i".pdf -
# ^ ^ ^ ^
# | | | lossless conversion to pdf
# | | specify PNG
# | convert to png
# extract page
done
# The last part comes from
# https://unix.stackexchange.com/questions/42856/how-can-i-convert-a-png-to-a-pdf-in-high-quality-so-its-not-blurry-or-fuzzy
Info (by Pere)
viernes, 24 de abril de 2020
lunes, 22 de abril de 2019
Recover deleted files
Scenario: you had some files on your USB stick which you need to recover.
The tool to use is PhotoRec.
sudo apt install testdisk
sudo photorec
A guide is here.
lunes, 26 de febrero de 2018
Combining multiple pdf files
To combine multiple pdf files into a single one, use
pdftk A=doc1.pdf B=doc2.pdf C=doc3.pdf cat A1-9 B C A10-end output global.pdf
pdftk A=doc1.pdf B=doc2.pdf C=doc3.pdf cat A1-9 B C A10-end output global.pdf
sábado, 16 de septiembre de 2017
Extract page from pdf and convert to png
Extreure la pàgina que volem:
$ pdftk Caminant.pdf cat 1 output p1.pdf
Convertir-ho al que convingui, aquí en jpg
$ convert -units PixelsPerInch -density 300 p1.pdf p1_300.jpg
Si volem extreure totes les pàgines:
$ pdftk Caminant.pdf burst
Això ens crea un fitxer pg_xxxx.pdf per cada pàgina i un fitxer resum del que hi havia al pdf original
Ara, per convertir totes les pàgines de cop, podem fer:
for file in pg_*.pdf ; do convert -units PixelsPerInch -density 300 "$file" "${file%.*}.jpg" ; done
Combinació de pdftk i de convert en una línia:
$ pdftk A=filein.pdf cat A14 output - | convert -density 96 - fileout.png
Els guions substitueixen els noms que hi hauria:
- A pdftk faríem ... output output.pdf.
- A convert faríem convert ... filein.pdf fileout.png
Aquí es fa a 96 dpi, però es pot fer a més resolució, si interessa.
$ pdftk A=POG.pdf cat A14 output - | convert -density 96 - - | convert - pag14.pdf
Això es pot fer automatitzat
NPAGES=$(pdfinfo $1 | grep Pages | awk '{print $2}')
echo $NPAGES
for i in $(seq $NPAGES); do
echo Processing page $i
echo Generating "FILE$i".png
pdftk A=$1 cat "A$i" output - | convert -density 96 - "__FILE$i".png
done
domingo, 4 de junio de 2017
Octave: Fit Gaussian to data
% Adjust a gaussian
% Define the gaussian function
gausFun = @(hms,x) hms(1) .* exp (-(x-hms(2)).^2 ./ (2*hms(3)^2)) ;
init=[100;0;20]; % Hmax, mean, sigma
[P, FY, CVG, OUTP] = nonlin_curvefit (gausFun , init', XX, NN);
%Print estimated sigma
sigma_est=P(3)
viernes, 28 de abril de 2017
Raspberry pi zero W
Enable headless operation
- Download raspbian and write to micro-SD card
- Mount on PC and, on the boot partition:
- Create an (empty) file called ssh (this enable SSH on startup)
- Create a wpa_supplicant.conf file with the following content
network={
ssid="YOUR_WIFI_SSID"
psk="YOUR_WIFI_PASSWORD"
key_mgmt=WPA-PSK
}
On Off button
Poweroff
To poweroff, follow these instructions:
Essentially:
Connect button between GPIO18 and GND
Write this python script
- #!/bin/python
- # Simple script for shutting down the raspberry Pi at the press of a button.
- # by Inderpreet Singh
- import RPi.GPIO as GPIO
- import time
- import os
- # Use the Broadcom SOC Pin numbers
- # Setup the Pin with Internal pullups enabled and PIN in reading mode.
- GPIO.setmode(GPIO.BCM)
- GPIO.setup(18, GPIO.IN, pull_up_down = GPIO.PUD_UP)
- # Our function on what to do when the button is pressed
- def Shutdown(channel):
- os.system("sudo shutdown -h now")
- # Add our function to execute when the button pressed event happens
- GPIO.add_event_detect(18, GPIO.FALLING, callback = Shutdown, bouncetime = 2000)
- # Now wait!
- while 1:
- time.sleep(1)
- sudo nano /etc/rc.local
- sudo python /home/pi/Scripts/shutdown_pi.py &
Poweron
To poweron, place a button across the RUN header of the RPI zero. This is actually a reset button but when halted can bring the Pi on again.
Power Consumption
During boot, I have seen peaks of 240 mA.
After shutdown, power consumption is 30 mA.
sábado, 25 de marzo de 2017
SPICE with Python
PySpice seems to be a great tool!
Just do
git clone https://github.com/FabriceSalvaire/PySpice
and install everything that it needs:
PySpice requires the following dependencies:
The way to organize a project is to have the file.py, a folder called libraries and inside put folders with the element.lib files. These can also be put into folders to easily organize things. Then, call this
libraries_path = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'libraries')
spice_library = SpiceLibrary(libraries_path)
circuit.include(spice_library['2n2222a'])
circuit.BJT(1, 'collector', 'base', circuit.gnd, '2n2222a')
Resistor
circuit.R( name, +node, -node, value)
circuit.R(1, 'out', circuit.gnd, kilo(5))
Capacitor
circuit.C(1, +node, -node, value)
circuit.C(1, +node, -node, value, initial_condition=5)
BJT
circuit.BJT(1, 'collector', 'base', circuit.gnd, '2n2222a')
Results
analysis.base : the voltage of node named 'base'
Interesting features
https://github.com/FabriceSalvaire/PySpice/blob/gh-pages/downloads/voltage-divider.py
Shows how to put a voltage source defined in Python into Spice. This probably means that you can have an arbitrary function generator in Python!!!
Just do
git clone https://github.com/FabriceSalvaire/PySpice
and install everything that it needs:
PySpice requires the following dependencies:
- Python 3
- Numpy
- Matplotlib
- Ngspice
- CFFI (only required for Ngspice shared)
The way to organize a project is to have the file.py, a folder called libraries and inside put folders with the element.lib files. These can also be put into folders to easily organize things. Then, call this
libraries_path = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'libraries')
spice_library = SpiceLibrary(libraries_path)
circuit.include(spice_library['2n2222a'])
circuit.BJT(1, 'collector', 'base', circuit.gnd, '2n2222a')
Resistor
circuit.R( name, +node, -node, value)
circuit.R(1, 'out', circuit.gnd, kilo(5))
Capacitor
circuit.C(1, +node, -node, value)
circuit.C(1, +node, -node, value, initial_condition=5)
BJT
circuit.BJT(1, 'collector', 'base', circuit.gnd, '2n2222a')
Results
analysis.base : the voltage of node named 'base'
Interesting features
https://github.com/FabriceSalvaire/PySpice/blob/gh-pages/downloads/voltage-divider.py
Shows how to put a voltage source defined in Python into Spice. This probably means that you can have an arbitrary function generator in Python!!!
domingo, 5 de febrero de 2017
Coses sobre l'esquena i els isquiotibials
https://breakingmuscle.com/learn/2-overlooked-reasons-your-hamstrings-are-tight
https://breakingmuscle.com/learn/cant-touch-your-toes-find-and-fix-the-root-of-the-problem
https://breakingmuscle.com/learn/are-your-weak-neck-muscles-making-your-hamstrings-tight
viernes, 3 de febrero de 2017
Arduino. On és el main?
Exactament què fa un programa en Arduino?
Executa un loop com aquest: https://github.com/arduino/Arduino/blob/master/hardware/arduino/avr/cores/arduino/main.cpp
int main(void) {
init();
initVariant();
setup();
for (;;) {
loop();
if (serialEventRun) serialEventRun();
}
return 0;
}
Executa una vegada el setup de client i crida repetidament loop() més serialEventRun.
Tot el codi principal està aquí https://github.com/arduino/Arduino/tree/master/hardware/arduino/avr/cores/arduino
Un element important és Arduino.h (en les versions "modernes" de Arduino).
jueves, 2 de febrero de 2017
Flight Controller
One of the best tutorials I have found on flight controllers
http://blog.owenson.me/build-your-own-quadcopter-flight-controller/
http://blog.owenson.me/build-your-own-quadcopter-flight-controller/
Suscribirse a:
Entradas (Atom)