// Place your key bindings in this file to override the defaults
[
{
"key": "left",
"command": "cursorLeft",
"when": "textInputFocus"
},
{
"key": "alt+h",
"command": "cursorLeft"
},
{
"key":"ctrl+alt+h",
"command":"cursorWordLeft"
},
{
"key":"shift+ctrl+alt+h",
"command":"cursorWordLeftSelect"
},
{
"key": "right",
"command": "cursorRight",
"when": "textInputFocus"
},
{
"key": "alt+l",
"command": "cursorRight"
},
{
"key":"ctrl+alt+l",
"command":"cursorWordRight"
},
{
"key":"shift+ctrl+alt+l",
"command":"cursorWordRightSelect"
},
{
"key": "up",
"command": "cursorUp",
"when": "textInputFocus"
},
{
"key": "alt+k",
"command": "cursorUp"
},
{
"key":"shift+ctrl+alt+k",
"command":"cursorUpSelect"
},
{
"key": "down",
"command": "cursorDown",
"when": "textInputFocus"
},
{
"key": "alt+j",
"command": "cursorDown"
},
{
"key":"shift+ctrl+alt+j",
"command":"cursorDownSelect"
}
]
Customise Visual Studio Code Shortcuts
Visual Studio Posted on 03 Jul, 2023 21:20:52- Comments(0) https://www.guivi.one/?p=234
- Share
Do chmod 400 in windows
AWS EC2 Posted on 13 Apr, 2023 10:02:31icacls.exe your_key_name.pem /reset
icacls.exe your_key_name.pem /grant:r "$($env:username):(r)"
icacls.exe your_key_name.pem /inheritance:r
- Comments(0) https://www.guivi.one/?p=231
- Share
Simple NMEA Parsing
C/C++ Programming Posted on 05 Apr, 2023 13:39:58#include <iostream>
#include <map>
#include <sstream>
#include <string>
#include <vector>
std::string GetFieldId(std::string sentenceId, int fieldIndex)
{
// Combine the sentence ID and field index to create the field ID
std::ostringstream oss;
oss << sentenceId << "-" << fieldIndex;
return oss.str();
}
std::vector<std::string> SplitString(std::string str, char delimiter)
{
std::vector<std::string> parts;
std::stringstream ss(str);
std::string part;
while (std::getline(ss, part, delimiter)) {
parts.push_back(part);
}
return parts;
}
std::map<std::string, std::string> ParseNmeaString(std::string nmeaString)
{
std::map<std::string, std::string> components;
if (nmeaString.length() < 7 || nmeaString[0] != '$' || nmeaString[nmeaString.length()-3] != '*') {
return components;
}
std::string sentence = nmeaString.substr(1, nmeaString.length()-4);
std::string checksum = nmeaString.substr(nmeaString.length()-2, 2);
std::vector<std::string> parts = SplitString(sentence, ',');
std::string sentenceId = parts[0];
for (int i = 1; i < parts.size(); i++) {
components[GetFieldId(sentenceId, i)] = parts[i];
}
return components;
}
int main()
{
std::string sentence = "$GPGGA,092750.000,5321.6802,N,00630.3372,W,1,8,1.03,61.7,M,55.2,M,,*76";
std::map<std::string, std::string> components = ParseNmeaString(sentence);
// Print the components to the console
for (auto const& component : components) {
std::cout << component.first << ": " << component.second << std::endl;
}
return 0;
}
- Comments(0) https://www.guivi.one/?p=228
- Share
How do I give www-data user to a folder in my home folder?
Web Development Posted on 05 Apr, 2023 13:37:23First, add yourself into the group www-data
usermod -a -G www-data (your username)
Then:
chgrp www-data /home/myuser/folderA
chmod g+rwxs /home/myuser/folderA
Should do the trick unless the permissions on your /home/myuser
do not permit other users access.
The first command changes the group ownership of the folder to that of the webserver. The second command gives members of the www-data
group read, write, enter-directory rights, and the group s
flag will ensure that any files that get created inside that directory take www-data
as the group – so if you create a file as myuser
the www-data
user will have access.
Nb. this also depends on the umask
settings of both your user account and the webserver: you need to make sure that files created in folderA have group rw
access (and directories created within need group rwx
)
If your webserver does not have enter rights into your /home/myuser
dir (quite sensible) then it’s not going to get in there unless you do something else. Two solns:
sudo mount --bind /home/myuser/folderA /var/www/mysite/folderA
(this is an ugly hack and would have to be repeated after reboot. But a powerful trick, also can be used to make folders accessible inside SSH jails.)- Simply move the shared folder somewhere else, e.g.
/home/shared-stuff/folderA
.
The 2nd option is nicest. Let’s say the stuff in folderA is really public and you don’t care who sees it, you can set it up like
sudo mkdir -m777 /home/shared-stuff
Then you can put inside that, say, folderA with permissions as above, and folderB that www-data should not have access to with different permissions, e.g.
$ cd /home/shared-stuff ; ls -l
drwxrwsr-x 2 myuser www-data 4096 Jan 17 21:46 folderA
drwxrwx--- 2 myuser myuser 4096 Jan 17 21:46 folderB
Source: https://askubuntu.com/a/244410/957246
- Comments(0) https://www.guivi.one/?p=225
- Share
C# modern look ComboBox
C#, Modern GUI Posted on 27 Feb, 2023 07:31:21This is the code from a YouTube video on how to make a modern looking ComboBox. It is also an informative video on how to use already existing classes and the functions they have.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.ComponentModel;
using System.Drawing.Design;
namespace Test
{
[ToolboxItem(true)]
[DefaultEvent("OnSelectedIndexChanged")]
class MyComboBox : UserControl
{
private Color backColor = Color.MediumSlateBlue;
private Color iconColor = Color.WhiteSmoke;
private Color listBackColor = Color.FromArgb(230, 228, 245);
private Color listTextColor = Color.DimGray;
private Color borderColor = Color.MediumSlateBlue;
private int borderSize = 1;
// Item
private ComboBox cmbList;
private Label lblText;
private Button btnIcon;
// Properties
//-> Appearance
[Category("Appearance")]
public new Color BackColor
{
get => backColor;
set
{
backColor = value;
lblText.BackColor = backColor;
btnIcon.BackColor = backColor;
}
}
[Category("Appearance")]
public Color IconColor
{
get => iconColor;
set
{
iconColor = value;
btnIcon.Invalidate();
}
}
[Category("Appearance")]
public Color ListBackColor
{
get => listBackColor;
set
{
listBackColor = value;
cmbList.BackColor = listBackColor;
}
}
[Category("Appearance")]
public Color ListTextColor
{
get => listTextColor;
set
{
listTextColor = value;
cmbList.ForeColor = listTextColor;
}
}
[Category("Appearance")]
public Color BorderColor
{
get => borderColor;
set
{
borderColor = value;
base.BackColor = borderColor;
}
}
[Category("Appearance")]
public int BorderSize
{
get => borderSize;
set
{
borderSize = value;
this.Padding = new Padding(borderSize);
AdjustComboBoxDimensions();
}
}
[Category("Appearance")]
public override Color ForeColor
{
get => base.ForeColor;
set
{
base.ForeColor = value;
lblText.ForeColor = value;
}
}
[Category("Appearance")]
public override Font Font
{
get => base.Font;
set
{
base.Font = value;
lblText.Font = value;
cmbList.Font = value;
}
}
[Category("Appearance")]
public string Texts
{
get { return lblText.Text; }
set { lblText.Text = value; }
}
[Category("Appearance")]
public ComboBoxStyle DropDownStyle
{
get => cmbList.DropDownStyle;
set
{
if (cmbList.DropDownStyle != ComboBoxStyle.Simple)
cmbList.DropDownStyle = value;
}
}
//-> Data
[Category("Data")]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
[Editor("System.Windows.Forms.Design.ListControlStringCollectionEditor, System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", typeof(UITypeEditor))]
[Localizable(true)]
[MergableProperty(false)]
public ComboBox.ObjectCollection Items
{
get => cmbList.Items;
}
[Category("Data")]
[AttributeProvider(typeof(IListSource))]
[DefaultValue(null)]
[RefreshProperties(RefreshProperties.Repaint)]
public object DataSource
{
get { return cmbList.DataSource; }
set { cmbList.DataSource = value; }
}
[Category("Data")]
[Browsable(true)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
[Editor("System.Windows.Forms.Design.ListControlStringCollectionEditor, System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", typeof(UITypeEditor))]
[EditorBrowsable(EditorBrowsableState.Always)]
[Localizable(true)]
public AutoCompleteStringCollection AutoCompleteCustomSource
{
get { return cmbList.AutoCompleteCustomSource; }
set { cmbList.AutoCompleteCustomSource = value; }
}
[Category("Data")]
[Browsable(true)]
[DefaultValue(AutoCompleteSource.None)]
[EditorBrowsable(EditorBrowsableState.Always)]
public AutoCompleteSource AutoCompleteSource
{
get { return cmbList.AutoCompleteSource; }
set
{
cmbList.AutoCompleteSource = value;
}
}
[Category("Data")]
[Browsable(true)]
[DefaultValue(AutoCompleteMode.None)]
[EditorBrowsable(EditorBrowsableState.Always)]
public AutoCompleteMode AutoCompleteMode {
get { return cmbList.AutoCompleteMode; }
set
{
cmbList.AutoCompleteMode = value;
}
}
[Category("Data")]
[Bindable(true)]
[Browsable(false)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public object SelectedItem
{
get => cmbList.SelectedItem;
set => cmbList.SelectedItem = value;
}
[Category("Data")]
[Browsable(false)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public int SelectedIndex
{
get => cmbList.SelectedIndex;
set => cmbList.SelectedIndex = value;
}
//Events
public event EventHandler OnSelectedIndexChanged;
//constructor
public MyComboBox()
{
cmbList = new ComboBox();
lblText = new Label();
btnIcon = new Button();
this.SuspendLayout();
//ComoBox: Dropdown List;
cmbList.BackColor = listBackColor;
cmbList.Font = new Font(this.Font.Name, 10F);
cmbList.ForeColor = listTextColor;
cmbList.SelectedIndexChanged += new EventHandler(ComboBox_SelectedIndexChagned);
cmbList.TextChanged += new EventHandler(ComboBox_TextChanged);
//Buton: icon
btnIcon.Dock = DockStyle.Right;
btnIcon.FlatStyle = FlatStyle.Flat;
btnIcon.FlatAppearance.BorderSize = 0;
btnIcon.BackColor = backColor;
btnIcon.Size = new Size(30, 30);
btnIcon.Cursor = Cursors.Hand;
btnIcon.Click += new EventHandler( IconClick);
btnIcon.Paint += new PaintEventHandler( Icon_Paint);
// Lable:Text
lblText.Dock = DockStyle.Fill;
lblText.AutoSize = false;
lblText.BackColor = BackColor;
lblText.TextAlign = ContentAlignment.MiddleLeft;
lblText.Padding = new Padding(8, 0, 0, 0);
lblText.Font = new Font(this.Font.Name, 10F);
lblText.Click += new EventHandler(Surface_Click);
//User Control:
this.Controls.Add(lblText);
this.Controls.Add(btnIcon);
this.Controls.Add(cmbList);
this.MinimumSize = new Size(200, 30);
this.Size = new Size(200, 30);
this.ForeColor = Color.DimGray;
this.Padding = new Padding(borderSize);
base.BackColor = borderColor;
this.ResumeLayout();
AdjustComboBoxDimensions();
}
// Private Methods
private void AdjustComboBoxDimensions()
{
cmbList.Width = lblText.Width;
cmbList.Location = new Point()
{
X = this.Width - this.Padding.Right - cmbList.Width,
Y = lblText.Bottom - cmbList.Height
};
}
private void Surface_Click(object sender, EventArgs e)
{
// Select a combo box
cmbList.Select();
if (cmbList.DropDownStyle == ComboBoxStyle.DropDown)
cmbList.DroppedDown = true;
}
private void Icon_Paint(object sender, PaintEventArgs e)
{
//Field
int iconWidth = 14;
int iconHeight = 6;
var rectIcon = new Rectangle((btnIcon.Width - iconWidth) / 2, (btnIcon.Height - iconHeight) / 2, iconWidth, iconHeight);
Graphics graph = e.Graphics;
//Craw down arrow
using (GraphicsPath path = new GraphicsPath())
using (Pen pen = new Pen(iconColor, 2))
{
graph.SmoothingMode = SmoothingMode.AntiAlias;
path.AddLine(rectIcon.X, rectIcon.Y, rectIcon.X + (iconWidth / 2), rectIcon.Bottom);
path.AddLine(rectIcon.X +(iconWidth / 2), rectIcon.Bottom, rectIcon.Right, rectIcon.Y);
graph.DrawPath( pen, path);
}
}
private void IconClick(object sender, EventArgs e)
{
cmbList.Select();
cmbList.DroppedDown = true;
}
private void ComboBox_TextChanged(object sender, EventArgs e)
{
lblText.Text = cmbList.Text;
}
private void ComboBox_SelectedIndexChagned(object sender, EventArgs e)
{
if (OnSelectedIndexChanged != null)
OnSelectedIndexChanged.Invoke( sender, e);
lblText.Text = cmbList.Text;
}
}
}
- Comments(0) https://www.guivi.one/?p=222
- Share
On Mouse Leave MFC
C/C++ Programming, MFC Posted on 18 Feb, 2023 09:57:18simple article about how to use ON_WM_MOUSELEAVE leave on a button.
The button has to track the mouse while moues move (ON_WM_MOUSEMOVE) is called.
void CMYButton::OnMouseMove(UINT nFlags, CPoint point)
{
if (!m_bTracking)
{
TRACKMOUSEEVENT tme;
tme.cbSize = sizeof(tme);
tme.hwndTrack = m_hWnd;
tme.dwFlags = TME_LEAVE|TME_HOVER;
tme.dwHoverTime = 1;
m_bTracking = _TrackMouseEvent(&tme);
m_point = point;
}
LRESULT CMYButton::OnMouseHover(WPARAM wparam, LPARAM lparam)
{
m_txtInfo->SetWindowText(m_strInformation);
return m_bTracking;
}
LRESULT CMYButton::OnMouseLeave(WPARAM wparam,LPARAM lparam)
{
m_txtInfo->SetWindowText("");
m_bTracking = FALSE;
return 0;
}
Source:
https://microsoft.public.vc.mfc.narkive.com/YBQSIfWf/on-mouseleave-and-cbutton-with-windows-xp-desktop-theme
- Comments(0) https://www.guivi.one/?p=219
- Share
Silent boot with splash Raspberry PI
Pi Stuff Posted on 08 Feb, 2023 13:09:38sudo nano /boot/cmdline.txt
dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 console=tty3 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait loglevel=3 quiet logo.nologo
add "disable_splash=1" to /boot/config.txt
add "disable_overscan=1" to /boot/config.tx
------------------------------------------------------------------
place an image as splashscreen
install fbi: sudo apt install fbi
Creat the service file: /etc/systemd/system/splashscreen.service
Edit the service file to have the following content:
[Unit]
Description=Splash screen
DefaultDependencies=no
After=local-fs.target
[Service]
ExecStart=/usr/bin/fbi -d /dev/fb0 --noverbose -a /opt/splash.png
StandardInput=tty
StandardOutput=tty
[Install]
WantedBy=sysinit.target
Change location of the image accordengly.
Enable the service: sudo systemctl enable splashscreen
- Comments(0) https://www.guivi.one/?p=216
- Share
Minimal kiosk
Pi Stuff Posted on 16 Jan, 2023 10:19:03Steps:
Install the lite version of raspbian and make it boot to console with autoogin.
sudo apt-get update -qq
sudo apt-get install --no-install-recommends xserver-xorg-video-all \
xserver-xorg-input-all xserver-xorg-core xinit x11-xserver-utils \
chromium-browser unclutter
# Go to: Boot Options > Console Autologin
sudo raspi-config
Next edit /home/pi/.bash_profile
to automatically start the gui. There’s a check for the bash context first, so you don’t accidentally start chromium whenever you ssh in. This below may not be needed.
if [ -z $DISPLAY ] && [ $(tty) = /dev/tty1 ]
then
startx
fi
The last bit is to setup /home/pi/.xinitrc
to run chromium whenever you run startx. Here’s the full list of chromium arguments.
#!/usr/bin/env sh
xset -dpms
xset s off
xset s noblank
unclutter &
chromium-browser https://yourfancywebsite.com \
--window-size=1920,1080 \
--window-position=0,0 \
--start-fullscreen \
--kiosk \
--incognito \
--noerrdialogs \
--disable-translate \
--no-first-run \
--fast \
--fast-start \
--disable-infobars \
--disable-features=TranslateUI \
--disk-cache-dir=/dev/null \
--overscroll-history-navigation=0 \
--disable-pinch
It disables the cursor and screensaver. Then runs chromium with *all* of the flags. Set https://yourfancywebsite.com
to the website which you want to display. And set --window-size
to the size of your display (it’s horizontal first and vertical after the comma).
You may also want to uncomment disable_overscan=1 in /boot/config.txt so that the pi boots up using the full display.
Now whenever the pi boots up it’ll go into the console then on into chromium. If you want to exit you can hit Alt+F4
, then enter startx
to start up the browser again.
- Comments(0) https://www.guivi.one/?p=212
- Share