Skip to content

Instantly share code, notes, and snippets.

Avatar

Michael Penrod nerdybeast

View GitHub Profile
@nerdybeast
nerdybeast / autofs
Created Apr 25, 2020
Automount a windows share (via cifs) on Ubuntu-based system
View autofs
Problem: Need to access Windows share but only when on the company vpn.
- Tried mounting via fstab but the mount failed because I'm not automatically connected to the vpn when logged in
- Created a bash alias that simply mounts the share, the problem is that it's cumbersome to start the vpn then remember to run the mount command.
Autofs is a great option as it will automount that windows share only if I try and access it.
# Has to install it (Linux Mint 19)
sudo apt install autofs
# Opended the "/etc/auto.master" file the install created and added this line:
@nerdybeast
nerdybeast / fiddler
Created Apr 5, 2020
Get fiddler working on Linux Mint
View fiddler
Download the fiddler app image from Telerik site
Place app image somewhere (I have a folder called "app-images")
Make the app image executable (chmod +x <filename>.appimage)
Run fiddler and enable htttps traffic decryption: Settings => HTTPS => Decrypt Https Traffic
- This will give the option to export a self-signed ssl cert from Fiddler and it will place that in the desktop folder
Add the ssl cert to the system using these instructions: https://forums.linuxmint.com/viewtopic.php?t=256739
I did:
- sudo mkdir /usr/share/ca-certificates/fiddler
- sudo cp ~/Desktop/fiddler.crt /usr/share/ca-certificates/fiddler/fiddler.crt
@nerdybeast
nerdybeast / try-catch.js
Last active Dec 11, 2017
Avoid unnecessary catch blocks
View try-catch.js
//Been seeing a lot of this lately in various repos. This is unnecessary because you're simply
//rethrowing the same error that would have been thrown anyway thus rendering your try/catch block useless:
try {
//execute some code..
} catch(error) {
throw error;
}
//The only reason to catch an error is to either handle that error or log it:
try {
@nerdybeast
nerdybeast / AppSettings.cs
Last active Nov 27, 2017
Cast app settings from web config in one shot
View AppSettings.cs
//Make this class static so that it is loaded in memory when the app starts
public static class AppSettings {
public static T Get<T>(string key) {
var appSetting = ConfigurationManager.AppSettings[key];
if (string.IsNullOrWhiteSpace(appSetting)) throw new AppSettingNotFoundException(key);
var converter = TypeDescriptor.GetConverter(typeof(T));
return (T)(converter.ConvertFromInvariantString(appSetting));
}
@nerdybeast
nerdybeast / index.js
Created Nov 6, 2016
Euler 8 - Largest Product in a Series
View index.js
'use strict';const MAX = 13;const n = `    73167176531330624919225119674426574742355349194934    96983520312774506326239578318016984801869478851843    85861560789112949495459501737958331952853208805511    12540698747158523863050715693290963295227443043557    66896648950445244523161731856403098711121722383113    62229893423380308135336276614282806444486645238749    30358907296290491560440772390713810515859307960866    70172427121883998797908792274921901699720888093776    65727333001053367881220235421809751254540594752243    52584907711670556013604839586446706324415722155397    53697817977846174064955149290862569321978468622482    83972241375657056057490261407972968652414535100474    82166370484403199890008895243450658541227588666881    16427171479924442928230863465674813919123162824586    17866458359124566529476545682848912883142607690042    24219022671055626321111109370544217506941658960408    07198403850962455444362981230987879927244284909188    84580156166097919133875499200524063689912560717606    058861164
@nerdybeast
nerdybeast / index.js
Created Nov 6, 2016
Euler 7 - 10001'st Prime Number
View index.js
'use strict';
const MAX = 10001;
let primes = [];
let n = 2;
while(primes.length < MAX) {
if(isPrime(n)) { primes.push(n); }
if(n === 2) { n++; } else { n += 2; }
}
@nerdybeast
nerdybeast / index.js
Last active Nov 6, 2016
Euler 5 - Smallest Multiple
View index.js
'use strict';
const MIN = 1;
const MAX = 25;
let stillSearching = true;
let answer = MAX;
do {
let foundAnswer = true;
@nerdybeast
nerdybeast / index.js
Created Nov 6, 2016
Euler 6 - Sum Square Difference
View index.js
'use strict';
const MIN = 1;
const MAX = 100;
let sum = 0;
let sumOfSquares = 0;
for(var i = MIN; i <= MAX; i++) {
sum += i;
@nerdybeast
nerdybeast / index.js
Created Nov 6, 2016
Euler 4 - Largest Palindrome
View index.js
'use strict';
const MIN = 100;
const MAX = 999;
let largestPalindrome = 0;
let numOfPalindromes = 0;
let calculations = 0;
for(var i = MIN; i <= MAX; i++) {
@nerdybeast
nerdybeast / index.js
Last active Nov 5, 2016
Euler 3 - Largest Prime Factor
View index.js
'use strict';
function getPrimeFactors(n) {
   
let primeFactors = [];
   
while (n % 2 === 0) {
primeFactors.push(2);
n = n / 2;
}