Skip to content

Instantly share code, notes, and snippets.

View cmbaughman's full-sized avatar
🧐
I may be slow to respond.

Chris Baughman cmbaughman

🧐
I may be slow to respond.
View GitHub Profile
@cmbaughman
cmbaughman / find_date.md
Created February 1, 2024 15:39
Linux copy files based on date

To copy some files from one directory to another can be done kinda nicely with the find command.

  1. First define the start date: touch --date "2024-01-01" /tmp/start
  2. Define the end date: touch --date "2024-02-01" /tmp/end
  3. Now simply craft a find command like this:
find /var/logs/some_dir -type f -newer /tmp/start -not -newer /tmp/end -exec cp "{}" /opt/another/directory \;

NOTE: In the above command, the -exec part of the find uses "{}" as where it puts each filename

@cmbaughman
cmbaughman / win_network_linux.md
Created November 8, 2023 14:17
Notes on Ubuntu as a replacement for Windows AD DC server

Ubuntu as a replacement for Windows Network server

Set up an Ubuntu Server as a standalone Windows network server. In this scenario, we'll assume that you want to replace an existing Windows domain server with the Ubuntu server. Here are the steps:

  1. Install Ubuntu Server:

    • Start by downloading the Ubuntu Server ISO image from the official Ubuntu website.
    • Create a bootable USB drive or mount the ISO on your server.
    • Follow the installation prompts to install Ubuntu Server. During installation, choose the appropriate options for language, keyboard layout, and network configuration.
  2. Configure Network Settings:

@cmbaughman
cmbaughman / mysql_replication.md
Created November 8, 2023 13:41
Setting Up MySQL Replication

Setting Up MySQL Replication

Overview

We’ll configure one MySQL instance as the source database and another as its replica. Replication allows data synchronization between these separate databases.

Step 1: Configure the source

  1. Obviously install MySQL on 2 servers.
@cmbaughman
cmbaughman / gitconf.md
Last active August 3, 2023 15:34
Git Keep Line feeds even on Windows

Git Keep Line feeds even on Windows

  • Make sure Windows leaves your line endings alone. This way you can still run shell scripts and things in Git Bash or WSL: git config --global core.autocrlf input

  • Next, after committing any changes you do not have staged, run these:

git rm --cached -r .
git reset --hard
const SpotifyWebApi = require('spotify-web-api');
const fs = require('fs');
const os = require('os');
const readline = require('readline');
const spotify = new SpotifyWebApi({
clientId: 'YOUR_CLIENT_ID',
clientSecret: 'YOUR_CLIENT_SECRET',
redirectUri: 'http://localhost:3000',
});
@cmbaughman
cmbaughman / Reaper.bat
Last active April 20, 2023 14:20
Quick untested bat script to run reaper as admin
@echo off
set local
set runas=runas /user:Administrator
%runas% "c:\program files\reaper.exe"
%runas% explorer.exe
@cmbaughman
cmbaughman / compromisejs-name.js
Last active January 29, 2023 23:07
Using Compromise.js to get name formats right.
const nlp = require("compromise");
const nameParser = require("name-parser");
// Function to determine the name format
function determineNameFormat(name) {
// Patterns to match different name formats
const firstLast = nlp(name).match("#Honorific #FirstName #LastName").out("array");
const lastFirst = nlp(name).match("#LastName, #FirstName #Honorific").out("array");
const middleName = nlp(name).match("#FirstName #MiddleName #LastName").out("array");
const middleInitial = nlp(name).match("#FirstName #MiddleInitial #LastName").out("array");
@cmbaughman
cmbaughman / README.md
Created January 29, 2023 02:31
The JavaScript feature, Generators

Here is an example of using JavaScript generators to handle multiple HTTP requests in a sequential manner:

const fetch = require("node-fetch");

function* fetchUsers() {
  const user1 = yield fetch("https://jsonplaceholder.typicode.com/users/1");
 const user2 = yield fetch("https://jsonplaceholder.typicode.com/users/2");
@cmbaughman
cmbaughman / winshare.md
Created January 18, 2023 14:04
Mounting Windows Shares With CIFS

How To Use Windows Network Shares From Linux

This is the fastest way to set up Windows network (AD) shares with Linux using cifs-utils

Setup

  1. sudo apt update && sudo apt install cifs-utils -y
  2. sudo mkdir /mnt/win_share_name
  3. Create a credentials file: sudo nano /etc/win-credentials and enter the following contents:
@cmbaughman
cmbaughman / crowdsec-commands.md
Last active December 19, 2022 18:03
Crowdsec Commands

Useful Crowdsec Commands

Update

cscli hub update && cscli hub upgrade

Restart

systemctl restart crowdsec