Skip to content

Instantly share code, notes, and snippets.

View justinmklam's full-sized avatar

Justin Lam justinmklam

View GitHub Profile
//macro for detection af rasing edge
#define RE(signal, state) (state=(state<<1)|(signal&1)&3)==1
//macro for detection af falling edge
#define FE(signal, state) (state=(state<<1)|(signal&1)&3)==2
// Usage:
const int btn = 11; //btn pin
int btnState;
...
// Step 1: Go to forms designer, set AutoScaleMode property from Font (default) to Dpi
// Step 2: Add the following to Program.cs
static class Program
{
[STAThread]
static void Main()
{
if (Environment.OSVersion.Version.Major >= 6)
SetProcessDPIAware();
@justinmklam
justinmklam / create-installer-c#.md
Created May 17, 2019 21:53
Creating an installer for a C# application.

Creating an Installer for C# Winform

  1. Right click Solution and click Add New Project
  2. Select Setup Project under Other Project Types and click OK
  3. Right click installer project and click Add > Project Output
  4. Select Primary output and any other targets.
  5. If necessary, select Add > Files (ie. for icon, PDFs, other scripts, etc.)
  6. Fill in properties for installer project (ie. Company, Version, etc.)
    • Note: Version must be different for RemovePreviousVersion to work!
  7. Right click Primary output... and select Properties
@justinmklam
justinmklam / git-cheat-sheet.md
Last active March 26, 2021 06:41
Cheat sheet of useful git commands.

General

Set Default Configs

Omit --global to only set for a given repository. Omitting the value will show the currently set value.

# Editor
git config --global core.editor "vim"
  1. In repository, create ssh key pair under Settings > Pipelines > SSH Keys
  2. Add public key to through Google Cloud Platform compute engine admin console. Can't just add to ~/.ssh/authorized_keys because GCP must have some firewall settings that can't be bypassed.
  3. Optional: Add public key to repository under General > Access Keys. (Don't know if this is necessary though)
  4. Add deployment step to bitbucket-pipelines.yml.

Example file:

image: python:3.7.2
@justinmklam
justinmklam / linux-save-terminal-output.md
Created June 21, 2019 06:20
Handy table for the different options to save the output of a command to a file.

To write the output of a command to a file, there are basically 10 commonly used ways.

Please note that the n.e. in the syntax column means "not existing".

          || visible in terminal ||   visible in file   || existing
  Syntax  ||  StdOut  |  StdErr  ||  StdOut  |  StdErr  ||   file   
==========++==========+==========++==========+==========++===========
    >     ||    no    |   yes    ||   yes    |    no    || overwrite
    >>    ||    no    |   yes    ||   yes    |    no    ||  append
# Turn wifi off
iwconfig wlan0 txpower off
# Turn wifi back on
iwconfig wlan0 txpower auto
# Turn USB off
echo 0 | sudo tee /sys/devices/platform/soc/20980000.usb/buspower >/dev/null
# Turn USB on
@justinmklam
justinmklam / python-paths-and-imports.md
Last active May 7, 2024 21:05
Techniques for python path manipulation and relative imports in (i.e. when not dealing with a package).

Paths

import os

# To get the directory of the script/file:
current_dir = os.path.dirname(os.path.realpath(__file__))

# To get one directory up from the current file
parent_dir = os.path.abspath(os.path.join(current_dir, ".."))
/**
* @name someFunction
* @author
*
* Basic usage:
* var someFunction = new SomeFunction();
* someFunction.init();
*
* additionally you can use methods like someFunction.methodName();
*
@justinmklam
justinmklam / passwordless-ssh.md
Last active August 20, 2019 18:35
Set up passwordless ssh on a remote machine

Check if id_rsa.pub exists:

ls ~/.ssh

Generate new SSH keys (press enter all the way through):

ssh-keygen