Skip to content

Instantly share code, notes, and snippets.

@antriver
antriver / get-timezone.js
Created November 24, 2022 19:07
Get user's timezone
const getTimezoneName = () => {
try {
return Intl.DateTimeFormat().resolvedOptions().timeZone;
} catch (e) {
console.error('Failed to find the system timezone name.', e);
}
return null;
}
@antriver
antriver / set-wsl-ip.bat
Created April 21, 2022 12:43
Sets the WSL instance to a static IP address of 192.168.50.2 (from https://github.com/microsoft/WSL/issues/4210#issuecomment-856482892)
wsl -d Ubuntu -u root ip addr del $(ip addr show eth0 ^| grep 'inet\b' ^| awk '{print $2}' ^| head -n 1) dev eth0
wsl -d Ubuntu -u root ip addr add 192.168.50.2/24 broadcast 192.168.50.255 dev eth0
wsl -d Ubuntu -u root ip route add 0.0.0.0/0 via 192.168.50.1 dev eth0
wsl -d Ubuntu -u root echo nameserver 1.1.1.1 ^> /etc/resolv.conf
powershell -c "Get-NetAdapter 'vEthernet (WSL)' | Get-NetIPAddress | Remove-NetIPAddress -Confirm:$False; New-NetIPAddress -IPAddress 192.168.50.1 -PrefixLength 24 -InterfaceAlias 'vEthernet (WSL)'; Get-NetNat | ? Name -Eq WSLNat | Remove-NetNat -Confirm:$False; New-NetNat -Name WSLNat -InternalIPInterfaceAddressPrefix 192.168.50.0/24;"
@antriver
antriver / wsl-ip.sh
Last active April 28, 2021 12:03
Add a "wsl.local" entry to both the WSL and Windows hosts file, pointing to the IP address of WSL
#!/bin/bash
# You must run this script from an "elevated terminal", that means right click on Windows Terminal and "Run as Administrator".
# Then run it with `sudo wsl-ip.sh` from within WSL.
# Remove existing wsl.local lines
sed -i '/wsl.local/d' /etc/hosts
sed -i '/wsl.local/d' /mnt/c/Windows/system32/drivers/etc/hosts
# Add to WSL hosts file
#!/bin/bash
# Use this:
# export hostname=hello.world.com
# wget -O - https://gist.github.com/antriver/a38e8b18c3e491b5fd5caf1393a98ca4/raw | bash
#
# Use this script on a clean server to setup Puppet and then provision the server
# depending on its hostname. See instructions in README.md for usage.
#
# - Installs git (it already comes with 16.04 though!)
@antriver
antriver / fontawesome-migration.php
Created April 4, 2014 07:56
FontAwesome 3.2.1 to 4 name changes PHP array. Made with the list from https://github.com/FortAwesome/Font-Awesome/wiki/Upgrading-from-3.2.1-to-4
<?php
// 'old-fa3-name' => 'new-fa4-name'
$icons = array(
'ban-circle' => 'ban',
'bar-chart' => 'bar-chart-o',
'beaker' => 'flask',
'bell' => 'bell-o',
'bell-alt' => 'bell',
'bitbucket-sign' => 'bitbucket-square',
<?php
/**
* When user clicks the "yes, that's my email" link...
*/
//Make a unique key
$key = uniqid();
//Store in the database
@antriver
antriver / PHP array of cURL error codes and strings
Last active December 24, 2015 14:19
Here's an array of cURL error codes and their respective constant names as strings. If you're looking for an array of descriptions of cURL error codes then look here: http://drewsbox.com/php-snippets/php-array-of-curl-errors
<?php
$curl_error_codes = array (
0 => 'CURLE_OK',
1 => 'CURLE_UNSUPPORTED_PROTOCOL',
2 => 'CURLE_FAILED_INIT',
3 => 'CURLE_URL_MALFORMAT',
4 => 'CURLE_NOT_BUILT_IN',
5 => 'CURLE_COULDNT_RESOLVE_PROXY',
6 => 'CURLE_COULDNT_RESOLVE_HOST',
7 => 'CURLE_COULDNT_CONNECT',