If you receive No Space left error on Docker this the brute force solution:
It would stop and delete ALL containers, images and volumes.
docker stop $(docker ps -aq); docker rm $(docker ps -aq); docker volume rm $(docker volume ls -qf dangling=true);docker system prune -af
If you have to run the same command repetitively over different input/inputs.
Example input:
c595270372e3
c04094382ae1
498a6505a1f7
4ac0e1872789
170a7f2ec51a
930743cb4e19
Command:
pbpaste | xargs -I id docker image rm id
Note: pbpaste is clipboard paste command for Mac, would be different for operating systems.
A bit of a hack, but we want to be notified if an item becomes available at IKEA.
This is just a shell script that should work on any *NIX that has curl installed.
This is how their API response looks like (replace th with your country code): https://www.ikea.com/th/en/iows/catalog/availability/S99067497
There are only two stores in Thailand, both of which are close enough to the Oozou office, we only care that it's available in one of those stores.
#!/usr/bin/env bash
url="https://www.ikea.com/th/en/iows/catalog/availability/$1"
# This is the string that we want to see changed
string="0"
while true; do
# Get the API response and return as string
text=$(curl -s "$url")
# Get a count of how many times the substring matches
count=`grep -o "$string" <<< "$text" | wc -l`
# If less than 2, then it's available!
if (( $count < 2 )); then
echo "AVAILABLE, yay.";
# Notify us via Slack
curl -X POST --data-urlencode "payload={\"channel\": \"…\", \"username\": \"ikea\", \"text\": \"Item $1 is now available at IKEA.\", \"icon_emoji\": \":shooping_bags:\"}" https://hooks.slack.com/services/…
break
else
# If not available, sleep for 30s
echo "$1 not in stock"
sleep 30
fi
done
Pass in your item ID to start:
$ ./check.sh S99067497
const a = document.createElement('a')
a.setAttribute('class', 'foo bar')
a.setAttribute('id', 'id')
a.setAttribute('innerHTML', 'Hello World!')
a.setAttribute('href', 'https://www.google.com/')
Object.assign(document.createElement('a'), {
id: 'id',
class: 'whatever class',
href: 'https://www.google.com/',
innerHTML: 'This is a link'
});
const attributes = {
id: 'id',
class: 'foo bar',
href: 'https://www.google.com/',
innerHTML: 'Hello World!'
};
const a = Object.assign(document.createElement('a'), {...attributes});
function createElement(tag, attributes) {
return Object.assign(document.createElement(tag), attributes);
}
const a = createElement('a', {
id: 'id',
class: 'foo bar',
href: 'https://www.google.com/',
innerHTML: 'Hello World!'
});
You can switch Ruby version temporarily with rbenv local
But it'd need to be switched back after you're done. Specially for a single command it's kind of pain. In those cases, you can use RBENV_VERSION env variable.
RBENV_VERSION=2.6.3 ruby -v
This might be useful in a shell script or so.
select max(id) from users; +-----+ | max | +-----+ | 896 | +-----+ 1 rows in set (0.03 sec)
delete from users where created_at > timestamp 'yesterday'; 96 rows in set (0.15 sec)
select setval('users_id_seq',(select max(id) from users)); +--------+ | setval | +--------+ | 800 | +--------+ 1 rows in set (0.04 sec)
Occasionally an SSH session may become unresponsive. If I put my laptop to sleep this happens fairly often. Rather than killing the tab you can use SSH Escape Characters to kill the session
$ ~.
To view all escape characters check man ssh and search for ESCAPE CHARACTERS $ /ESCAPE CHARACTERS
This query shows how to use the PostgreSQL UPDATE join syntax to update data in a table based on values in another table. for example;
updating subscription_missions.giftbox_type with rewards.gift_box_type through mission_rewards table (tested on 300k records, crazy level fast)
UPDATE
subscription_missions sm
SET
giftbox_type = r.gift_box_type
FROM
mission_rewards mr,
rewards r
WHERE
sm.giftbox_type IS NULL
AND sm.id = mr.subscription_mission_id
AND mr.reward_id = r.id;
I'd like to kill rails running w/specific port. (My laptop running several rails servers. )
kill -9 $(lsof -i :3000|grep ruby|head -1|awk '{print $2}')