Skip to content

Instantly share code, notes, and snippets.

@facelordgists
facelordgists / JS: How to check if a variable exists.js
Last active November 2, 2018 17:33
JS: How to check if a variable exists.js #javascript #js
if (typeof subProduct != "undefined") {
console.log('subProduct exists');
}
// If doesn't exist
if (typeof subProduct == "undefined") {
console.log("subProduct doesn't exists");
}
@facelordgists
facelordgists / Angular: Remove $$hasKey from object in Angular.js
Created October 31, 2018 23:59
Angular adds this to keep track of your changes, so it knows when it needs to update the DOM, such as when using ng-repeat. Also, if you change your repeat expression to use the track by {uniqueProperty} suffix, Angular won't have to add $$hashKey at all.
$scope.myNewObject = JSON.parse(angular.toJson($scope.myObject))
@facelordgists
facelordgists / SSH into docker-compose service container.md
Last active June 12, 2019 19:15
Terminal: SSH into docker-compose service container.md

See: https://docs.docker.com/compose/reference/exec/

While in the same folder as a running docker container execute the following command:

docker-compose exec wp bash

For a much crappier shell, type this: docker-compose exec wp sh

in this example wp is the service defined in the docker-compose.yml

@facelordgists
facelordgists / How to recursively search folders for a string.sh
Created October 31, 2018 23:53
How to recursively search folders for a string using grep and ack
grep -r "string" .
# apparently capital R follows symlinks
grep -R "string" .
## Or use ACK
ack "string" folder
# Compiled source #
###################
*.com
*.class
*.dll
*.exe
*.o
*.so
# Packages #
@facelordgists
facelordgists / Terminal SCP Usage.sh
Last active February 2, 2019 01:58
how to use SCP
# Upload / copy a single file from the current local directory to the home dir of a remote server that's configured in your ssh config
scp test.txt gateway-team-orange:test.txt
# Download / copy a single file from the home dir of a remote server that's configured in your ssh config to your current local directory
scp cw-tuv:error-logs-all.log error-logs-all.log
# Copy a single file from one server to another (both in home directory)
scp gateway-team-green:test.txt gateway-team-orange:test.txt
@facelordgists
facelordgists / php-conditional-compare.php
Created July 20, 2017 18:49
PHP: Conditional compare function. Compare two values using conditional as an argument.
// usage:
// conditional_compare("bar", "=" "bar"); //returns true
// conditional_compare(123, "=" 123); //returns true
// conditional_compare(200, ">" 100); //returns true
// conditional_compare(100, ">" 200); //returns false
function conditional_compare($var1, $op, $var2) {
switch ($op) {
case "=": return $var1 == $var2;
case "!=": return $var1 != $var2;
case ">=": return $var1 >= $var2;
@facelordgists
facelordgists / .htaccess
Last active July 20, 2017 18:50
Redirect WordPress admin to temp page. Useful for migrating /migrate / migrations of WP installs
# Add these lines to your .htaccess file and upload migrating.html alongside it
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_URI} ^(.*)?wp-login\.php(.*)$ [OR]
RewriteCond %{REQUEST_URI} ^(.*)?wp-admin/(.*)$
#RewriteCond %{REMOTE_ADDR} !^123\.123\.123\.123$ #Add your IP address here if you want to whitelist it
RewriteRule ^(.*)$ /migrating.html [R=301,L]
</IfModule>
@facelordgists
facelordgists / Mobile typography SMS 2.x Upgrade.less
Created May 3, 2017 21:42
Responsive typography for upgrading SMS 1.x to 2.x
@media (max-width: 600px) {
.sms-heading--primary { font-size:4.2rem !important; }
h2.sms-heading--primary { font-size:3.2rem !important; }
h2, .sms-heading--secondary { font-size:2.6rem !important; }
h3.sms-heading--secondary { font-size:2rem !important; }
h3, .sms-heading--tertiary { font-size:2.2rem !important; }
.testimonial-basic .qhldr{
width: 100%;
margin-left: 0 !important;
margin-right: 0 !important;
@facelordgists
facelordgists / find-loop.sh
Created April 28, 2017 07:49
Terminal: while loop over files returned by find, get full path & filename
#!/bin/sh
file_path=~/Pictures/Photo\ Booth\ Library/Pictures
find "${file_path}" -name *.mov -not -name "*optimized*" -type f -print0 |
while IFS= read -r -d $'\0' full_file_path; do
file_name="${full_file_path##*/}"
echo "full_file_path: $full_file_path"
echo "file_name: $file_name"
done