Skip to content

Instantly share code, notes, and snippets.

View selfagency's full-sized avatar
👾
beep boop

daniel sieradski selfagency

👾
beep boop
View GitHub Profile
@selfagency
selfagency / find-tables-without-keys.sql
Created July 11, 2021 01:17
[find all tables without primary keys]
USE INFORMATION_SCHEMA;
SELECT
TABLES.table_name
FROM TABLES
LEFT JOIN KEY_COLUMN_USAGE AS c
ON (
TABLES.TABLE_NAME = c.TABLE_NAME
AND c.CONSTRAINT_SCHEMA = TABLES.TABLE_SCHEMA
AND c.constraint_name = 'PRIMARY'
)
@selfagency
selfagency / change-password-auth.sql
Created July 11, 2021 01:16
[change mysql 8 to mysql 5 password auth]
ALTER USER `root`@`%` IDENTIFIED WITH mysql_native_password BY [PASSWORD]
@selfagency
selfagency / find_iso_date.js
Created July 11, 2021 01:16
[find iso date regex]
const str = DATE_STRING
const isoDate = /(Sun\w*\.?|Mon\w*\.?|Tue\w*\.?|Wed\w*\.?|Thu\w*\.?|Fri\w*\.?|Sat\w*\.?)?\ ?(Jan\w*\.?|Feb\w*\.?|Mar\w*\.?|Apr\w*\.?|May\w*\.?|Jun\w*\.?|Jul\w*\.?|Aug\w*\.?|Sep\w*\.?|Oct\w*\.?|Nov\w*\.?|Dec\w*\.?)\ ?(\d+)?,? \ ?(\d{1,2}:\d{1,2}:?\d{2}?\ ?\w{3}\ ?)?(\d{4})/.exec(str)
@selfagency
selfagency / wp-config.php
Created July 11, 2021 01:14
[fix wordpress admin redirect]
<?php
define('FORCE_SSL_ADMIN', true);
if (strpos($_SERVER['HTTP_X_FORWARDED_PROTO'], 'https') !== false) {
$_SERVER['HTTPS'] = 'on';
}
@selfagency
selfagency / restart-nginx.sh
Created July 11, 2021 01:13
[restart nginx]
#!/usr/bin/env bash
sudo nginx -t && sudo systemctl reload nginx
@selfagency
selfagency / reverse_proxy.conf
Created July 11, 2021 01:13
[nginx reverse proxy]
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name selfagency.net;
# SSL
ssl_certificate /etc/letsencrypt/live/selfagency.net/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/selfagency.net/privkey.pem;
ssl_trusted_certificate /etc/letsencrypt/live/selfagency.net/chain.pem;
@selfagency
selfagency / nginx-with-certbot.sh
Created July 11, 2021 01:11
[config nginx with certbot]
#!/usr/bin/env bash
$DOMAIN=selfagency.dev
[email protected]
sudo sed -i -r 's/(listen .*443)/\1;#/g; s/(ssl_(certificate|certificate_key|trusted_certificate) )/#;#\1/g' /etc/nginx/sites-available/$DOMAIN.conf
sudo certbot certonly --webroot -d $DOMAIN --email $EMAIL -w /var/www/_letsencrypt -n --agree-tos --force-renewal
sudo sed -i -r 's/#?;#//g' /etc/nginx/sites-available/$DOMAIN.conf
sudo nginx -t && sudo systemctl reload nginx
@selfagency
selfagency / preload-svg.html
Created July 11, 2021 01:10
[preload svg]
<iframe src="signal.svg" onload="this.before(this.contentDocument.children[0]); this.remove();"></iframe>
@selfagency
selfagency / if-cli-else.js
Created July 11, 2021 01:09
[if node app is cli, else]
if (require.main === module) {
console.log('called directly');
} else {
console.log('required as a module');
}
@selfagency
selfagency / minimal-ga.html
Created July 11, 2021 01:08
[minimal google analytics]
<script>
(function(a,b,c){var d=a.history,e=document,f=navigator||{},g=localStorage,
h=encodeURIComponent,i=d.pushState,k=function(){return Math.random().toString(36)},
l=function(){return g.cid||(g.cid=k()),g.cid},m=function(r){var s=[];for(var t in r)
r.hasOwnProperty(t)&&void 0!==r[t]&&s.push(h(t)+"="+h(r[t]));return s.join("&")},
n=function(r,s,t,u,v,w,x){var z="https://www.google-analytics.com/collect",
A=m({v:"1",ds:"web",aip:c.anonymizeIp?1:void 0,tid:b,cid:l(),t:r||"pageview",
sd:c.colorDepth&&screen.colorDepth?screen.colorDepth+"-bits":void 0,dr:e.referrer||
void 0,dt:e.title,dl:e.location.origin+e.location.pathname+e.location.search,ul:c.language?
(f.language||"").toLowerCase():void 0,de:c.characterSet?e.characterSet:void 0,