Showing posts with label Computers. Show all posts
Showing posts with label Computers. Show all posts

Saturday, November 02, 2019

Formatting Code on Blogs...

Finally found at how to do this using prism.js from the excellent blog post here.

This is done by adding a link to the CSS in <head>, and a link to the JS before closing the <body> tag. The theme is specified with the css name, e.g. prism.min.css or prism-tomrrow.min.css. For Blogger, this has to be done by updating the Blog Theme.

<head>
  ...
  <link
    href='https://cdnjs.cloudflare.com/ajax/libs/prism/1.17.1/themes/prism-tomorrow.min.css' 
    rel='stylesheet'/>
</head>
<body>
  ...
  <script
    src='https://cdnjs.cloudflare.com/ajax/libs/prism/1.17.1/prism.min.js'/>
  <script
    src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.17.1/plugins/autoloader/prism-autoloader.min.js"/>
</body>

There is a full list of the CDN files here, and a full list of supported languages here.

Code is enclosed within the <pre> tag to preserve formatting; and within the <code> tags, also specifying the language for highlighting:

<pre><code class="language-java">   class App {
      public static void main(String[] args) {
         System.out.println("Hello World!");
      }
   }
</code></pre>

Formatting can also be done inline.

Note that to display HTML or PHP some of the symbols will need to be escaped so the browser doesn't try to parse the code. An online converter like Free Online HTML Escape Tool can do this.

Wednesday, October 09, 2019

Installing MicroPython on the ESP8266

Check the port it is attached to in Device Manager. Download the firmware from the MicroPython downloads page.
Open a Command Prompt and do the following:
pip install esptool

# erase the flash

esptool.py --chip esp8266 erase_flash

# For the HUZZAH ESP8266 breakout buttons for GPIO0 and RESET are built in to the board
# Hold GPIO0 down, then press and release RESET (while still holding GPIO0),
# and finally release GPIO0

# install the firmware
esptool.py --chip esp8266 --port COM3 write_flash --flash_mode dio \
   --flash_size detect 0x0 esp8266-20190529-v1.11.bin
Full info on the Adafruit HUZZAH ESP8266 breakout on the Adafruit website.
Full info on MicroPython here.
Connection to the REPL over the serial prompt is at baudrate 115200 using Putty.
Note that the USB to UART serial console cable is connected as follows:
  • n/a
  • White - Tx
  • Green - Rx
  • Red - V+
  • n/a
  • Black - GND

Sunday, January 06, 2019

VirtualBox: Creating a Centos VM...

Create the VM from the DVD ISO, including GNOME.

Make sure on Settings -> System -> Pointing Device is set to USB Tablet.

Then...

'visudo' and add the following: 'paul ALL=(ALL) NOPASSWD: ALL'

sudo yum install VBoxAdditions, gcc kernel-devel dkms perl, make
cd /run/media/****/VBOXADDITIONS*
sudo ./VBoxLiuxAdditions

sudo yum install java java-1.8-openjdk-devel git

in /etc/sysconfig/network-scripts/ifcfg-enp0s3 (or the appropriate network adaptor) set 'ONBOOT=yes'

mkdir ~/git
cd ~/git
git clone -u 'sh gup.sh' paulp@*****:d:/Users/****/Documents/git-server/miscellany.git

ln -sf ~/git/miscellany/vimrc ~/.vimrc
ln -sf ~/git/miscellany/bash_aliases ~/.bash_aliases
ln -sf ~/git/miscellany/gitconfig ~/.gitconfig

Set Terminal Custom Font to DejaVu Sans Mono Book (10 or 9)

Wednesday, December 19, 2018

Instagram Download Links

Hmmm..... this no longer appears to work. Needs reworking, and check here.

To view a full size Instagram picture, append

media/?size=l
, e.g.

https://www.instagram.com/p/B3hoo93BLA1UtIa4QJvMu1iyBPvX1PGbeH5XfI0/

should be updated to:

https://www.instagram.com/p/B3hoo93BLA1UtIa4QJvMu1iyBPvX1PGbeH5XfI0/media/?size=l

A simple Tampermonkey script to add a link to an Instagram page to allow the image to be downloaded.

// ==UserScript==
// @name Instagram Download Link
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Add a link to download photos....
// @author Me
// @match https://www.instagram.com/*
// @grant none
// @require https://code.jquery.com/jquery-3.3.1.min.js
// ==/UserScript==

var currentPage;
var domChangeTimer = '';
var listenerInstalled = false;

$(window).bind('load', MainAction);

function MainAction() {

  // add a listener to the page so this function is run each time the page changes...
  if (!listenerInstalled) {
    document.addEventListener("DOMSubtreeModified", HandleDomChange, false);
    listenerInstalled = true;
  }

  // check the current URL. This will change as AJAX changes the page...
  if (currentPage != window.location.href) {
    currentPage = window.location.href;

    // is the link to the image available...?
    var link = $('meta[property="og:image"]').attr('content');

    // if not, and the page is just of a single image
    // e.g. https://www.instagram.com/p/BuRxiC5Hr4i/
    // then reload the page so the link is available...
    // this is clumsy, but can't find another way to get at the DOM as updated by AJAX
    if (window.location.href.match(/\/p\//) && link == undefined) {
      window.location.reload();
    } else if (!window.location.href.match(/\/p\//) && link != undefined) {

      // and if we've just mmoved off a single image page
      // reload again to get rid of the image metadata from our copy of the DOM
      // that has since been updated by AJAX
      window.location.reload();
    }

    console.log("Download link : " + link);

    // if the link is available, add it to the page...
    if (link != undefined) {
      $("article").append("Download Link");
    }
  }
}

function HandleDomChange(zEvent) {

  // why do we do this here...?
  if (typeof domChangeTimer == "number") {
    clearTimeout(domChangeTimer);
    domChangeTimer = '';
  }

  // DOM has changed, so set a timer...
  // Note that this may be updated numerous times, but the function
  // will only be called when the timer hasn't been set for x ms
  domChangeTimer = setTimeout (function() {
    MainAction();
  }, 500); // in ms
}

Wednesday, November 28, 2018

Counting Files

A quick bash script to count the number of files in a set of directories:

DIRS=`ls -d */`
for D in $DIRS;
do
  printf "$D "
  find $D -type f|wc -l
done

Tuesday, November 27, 2018

MySQL Scheduling

Managing Events

Switch on the event scheduler in the database

SET GLOBAL event_scheduler=on;

To set it on startup, it is necessary to update "/etc/mysql/my.cnf" to add the following:

[mysqld]
event_scheduler = on

Create event to periodically update the database

USE temperatures;
CREATE DEFINER = 'root'@'localhost' event
  IF NOT EXISTS snapshot
ON SCHEDULE EVERY 15 minute STARTS '2018-11-27 00:00:00'
DO
  INSERT INTO temperatures.minmax
    SELECT curdate(), round(min(outside_temp), 1) as min, round(max(outside_temp), 1) AS max
      FROM temperatures.readings WHERE datetime > curdate()
    ON DUPLICATE KEY UPDATE
      min = min, max = max;
Show and delete events

SHOW EVENTS;
SHOW CREATE EVENT snapshot;
DROP EVENT snapshot;
SHOW PROCESSLIST;

Note that code blocks may need the delimiter to change to allow the client to accept nested statements:

DELIMITER //

BEGIN
  SELECT * FROM mytable;
END //

To show all events:

SHOW EVENTS;

To show existing event scripts for a given event

SHOW CREATE EVENT snapshot;

And to alter event scripts

ALTER EVENT snapshot
DO
[new code];

Wednesday, October 24, 2018

Basic MySQL

To get rid of the annoying Ctrl+c issue use mysql -u root -p --sigint-ignore

Managing Users

SELECT user, host FROM mysql.user;
CREATE USER 'user'@'server' IDENTIFIED BY 'mypassword';

SHOW GRANTS FOR 'user'@'server';
GRANT INSERT, SELECT, UPDATE ON stuff.* TO 'user'@'server';
REVOKE INSERT ON stuff.* from 'user'@'server';

DROP USER 'user'@'server';

Managing Databases

CREATE DATABASE stuff;
SHOW DATABASES;
USE stuff;
DROP DATABASE stuff;

Managing Tables

CREATE TABLE music (
  id INT unsigned NOT NULL AUTO_INCREMENT,
  artist VARCHAR(50) NOT NULL,
  title VARCHAR(50) NOT NULL,
  PRIMARY KEY (id)
);
SHOW TABLES;
DESCRIBE music;

ALTER TABLE music ADD release_date DATETIME AFTER title;
ALTER TABLE music CHANGE COLUMN release_date rel_d DATE NOT NULL;
ALTER TABLE music DROP COLUMN rel_d, RENAME TO media;

DROP TABLE music;

Managing Records

INSERT INTO music (artist, title) VALUES
  ('Prefab Sprout', 'Steve McQueen'),
  ('Elbow', 'Asleep at the Back');

SELECT COUNT(*) AS total FROM music WHERE artist LIKE 'Elb%';
SELECT * FROM music WHERE release_date IS NULL ORDER BY artist;
SELECT * FROM stuff WHERE datetime > curdate() - INTERVAL 1 DAY;
SELECT * FROM temperatures.readings
  WHERE pressure=(SELECT min(pressure) FROM temperatures.readings);

UPDATE music SET title='Cast of Thousands' WHERE title='Asleep at the Back';
DELETE FROM music WHERE artist='Elbow';

Tuesday, July 03, 2018

systemd

Time to move on from using the init daemon to manage starting and stopping processes and services.

systemd is a system management daemon that replaces init.d and is available on most distributions.

Fedora documentation can be found here.

To create a new service, create a new configuration file /etc/systemd/system/foo.service (note that absolute path names are required, even for interpreters etc.):

[Unit]
Description=My service
Requires=network.target mysql.service

[Service]
Type=simple
ExecStart=/usr/bin/java -Dapp.properties=/home/pi/clock.properties -jar /home/pi/clock-1.1.jar

[Install]
WantedBy=multi-user.target

To start:
sudo systemctl start foo

To enable on startup:
sudo systemctl enable foo

To check if enabled
sudo systemctl is-enabled foo

Monday, April 21, 2014

Getting the new Dell Working...

Lovely computer, but would prefer if it had worked out of the box!!

Flickering screen on batteries is fixed by switching off Display Power Saving Technology on Intel HD Graphics Control Panel (see thread here).

Then the laptop not coming out of sleep is ironically, the Intel Rapid Start Technology. This needs to be switched off...!

Sunday, April 20, 2014

Source Code Pro...

Currently enjoying the Source Code Pro font, which can be downloaded from here: the OTF version is the newest font type...

Note to stop xterm opening with cygwinx, type touch ~/.startxwinrc in the bash terminal. See here

Wednesday, August 07, 2013

Setting up the Slide Scanner

Always manage to struggle with this one, but you need to:

  • Connect scanner and power on before powering on PC
  • Install Hamrick Vuescan (free update period has ended, so stick with version 8.4.60) including the provided drivers
  • Unpack SCSI drivers (aic78xx_aic78u2_vista_x86_v605456.exe)
  • Through Device Manager, locate the SCSI card, and install the unpacked drivers
  • Register Vuescan, using the details in .\Assorted Stuff\Vuescan Account Details.pdf
And it should all work well, although the SCSI card appears to conflict with the sound card for some reason...

Wednesday, February 01, 2012

Chrome SE Linux fix...

From here:

# cat /var/log/audit/audit.log | grep chrome | audit2allow -m local > local.te
# make -f /usr/share/selinux/devel/Makefile
Compiling targeted local module
/usr/bin/checkmodule: loading policy configuration from tmp/local.tmp
/usr/bin/checkmodule: policy configuration loaded
/usr/bin/checkmodule: writing binary representation (version 10) to tmp/local.mod
Creating targeted local.pp policy package
rm tmp/local.mod.fc tmp/local.mod
# semodule -i local.pp

Saturday, October 29, 2011

Rebuilding Windows

I need to rebuild Windows again (it has been a few years now). So I will need to install:
Could take a while. And see here for the historical XP version...

Wednesday, August 24, 2011

Linux post-install...

Once it has been installed, there are a couple of things needed to make it a better experience.

These are (package names that can be used with yum):
  • google-chrome
  • vim-enhanced
  • kdebase (konsole)
  • kdesdk (kompare)
  • eclipse-platform
Also need to:
  • add "paul ALL=(ALL) NOPASSWD: ALL" using visudo
  • usermod -g vboxsf paul
  • ln -sf /media/sf_Documents ~/Documents
  • ln -sf /media/sf_Pictures ~/Pictures

Wednesday, July 27, 2011

VirtualBox Guest Additions...

It seems that sometimes they just stop working. So... to get them running on Fedora, the following instructions apply:
  • Install Guest Additions Virtual Drive: Devices-> Install Guest Additions (may have to Remove Disk from Virtual Drive then repeat to get Linux to auto mount).
  • su -
  • yum update
  • yum install dkms gcc
  • cd /media/VBOXADDITIONS*
  • sh ./VBoxLinuxAdditions.run
You may need to reinstall the appropriate kernel devel packge (it will tell you it can't find the correct files). And then restart the Guest machine...

Oh, and note that if you want GNOME3 to work, you need to select 3D acceleration in Virtual Box settings...

Wednesday, June 01, 2011

Backup Strategy...

I have noticed that Windows Backup only appears to back up files that have programs associated with their file extensions.

Which means that all my Perl files which were only run through Linux, weren't backed up.

I just think it's a little too clever for its own good...

Edit: on installing ActivePerl for Windows, Backup still doesn't backup these files. It appears maybe it is just not clever enough...

Sunday, February 13, 2011

Virtually...

So, my old 750MHz box which found a new lease of life with Linux may have just lost it again after installing VirtualBox on my main PC.

This allows the installation and execution of a Guest OS simultaneously with the Host OS.

Installation of a Linux Guest is easy. However, this only gives a screen resolution of 1024x800 for the Guest. To increase it, you need to update the Linux kernel and install VirtualBox Guest additions. Full instructions can be found here.

Also worth noting is that if you want to ssh into the Guest from the host, using NAT it is necessary to set up port forwarding (see VirtualBox User Manual section 6.3.1). Once this is done, it is necessary to ensure ssh is running on the Guest, and ssh in with the correct port, e.g. using Xming:

plink.exe -l user -p 2222 localhost

Finally, it is good to set up folder sharing so you can access all the files on the Host. This is explained in section 4.3 of the User Manual, and you just have to make sure that the user is in the vboxfs group using:
usermod -a -G vboxfs user

And that should give a full screen Guest OS with access to the Host directories wherever necessary without the overhead of maintaining either separate hardware, or a dual boot system. Brilliant!

Monday, August 16, 2010

Network Geography and Topology (Part 2)...

Setting up ICS wasn't so easy the second time, probably on the basis that I forgot to document some steps in the last post.

So, to do things properly, you have to set the router to IP address 192.168.2.x, so the wireless adapter on the Windows PC connects on an appropriate subnet.

Then, on the wireless internet connection, right click properties and enable ICS.

It is probably necessary to set the IP address of the wired adapter to 192.168.0.1, and on my Fedora installation, the Linux box sets itself up on 192.168.0.254.
From the Linux box, you should be able to ping the Windows box on 192.168.2.x, and a good check is to ping a website, the IP address of which can be obtained by pinging from the Windows PC (e.g. ping www.google.co.uk).

If that works, then you just need to set up the DNS addresses on the Linux box. These can be obtained from your ISP, or from the settings in the wireless router. And they are added to /etc/resolv.conf in the format "nameserver xxx.xxx.xxx.xxx", by adding DNS1=xxx.xxx.xxx.xxx to file /etc/sysconfig/network-scripts/ifcfg-eth0:1 (or whatever file as appropriate).

I'll probably struggle to do this a third time, so have to avoid rebuilding my machines...

Wednesday, March 24, 2010

Performance Issues...

So, after a Vista re-installation, a quick listen to the fan showed that the CPU was working overtime. Investigation with Windows Process Explorer showed that this was down to DPCs (Deferred Procedure Calls), but didn't show what was causing them.

Then I found this blog which very quickly identified the Intel 82562V Network Adapter as the cause. All you need to do is turn off all the Power saving and Wake-on-Lan settings in the Power Management tab of the Adapter properties.

Easy as that...!

Saturday, January 23, 2010

FeedDemon

Am currently liking FeedDemon, but not the adverts it subjects you to (unless you pay £9.83 to get rid of them). So good to find out how to disable them for free.

I guess I should be using a more web based solution, but I'm old fashioned: I like downloading stuff to my computer. Should try and grow out of that I suppose...