Skip to content

Instantly share code, notes, and snippets.

View himat's full-sized avatar
💭
Making

Hima himat

💭
Making
View GitHub Profile
@himat
himat / info.md
Created April 20, 2020 02:29
[deploy gcloud containers] Create containers that restart automatically (for Hasura)

This sets up a Postgres DB and Hasura container as a long-running instance that restarts automatically on failure

  • Spin up your SQL DB: gcloud sql instances create "$db_instance" --database-version=POSTGRES_11 --zone="${project_zone}" --tier=db-g1-small --storage-type=SSD --maintenance-window-day=sunday --maintenance-window-hour=00
  • Then set up your Hasura instance: gcloud compute instances create-with-container "$hasura_instance" --container-image="hasura/graphql-engine:latest" --machine-type=e2-micro --container-env-file="./hasura.env" --container-env HASURA_GRAPHQL_ADMIN_SECRET="$hasura_admin_secret",HASURA_GRAPHQL_ACCESS_KEY="$hasura_admin_secret",HASURA_GRAPHQL_DATABASE_URL="postgres://hasurauser:${hasura_db_pw}@${sql_ip}:5432/postgres" --zone="${project_zone}" --container-restart-policy=always --tags="http-server" --address="${hasura_fixed_ext_ip}"
  • You will additionally need to patch the SQL DB to allow the console to change firewall rules with: `yes | gcloud sql instances patch "$db_insta
@himat
himat / css_rules.js
Created October 15, 2020 15:16
[Get all CSS rules on a webpage] #javascript
Array.from(document.styleSheets).map(s => Array.from(s.cssRules)).flat().map(c => c.cssText).join("\n")
@himat
himat / find.js
Last active November 11, 2020 04:57
[Find which page stylesheet contains a certain css text] #javascript
for (var sheetI=0; sheetI<document.styleSheets.length; sheetI+=1) {
try {
var foundRule = Array.from(document.styleSheets[sheetI].cssRules).find(rule => rule.cssText.includes(".intercom-sg4b1o"));
console.log("found? doc", sheetI, " - ", foundRule);
} catch (error) { console.log(error); }
}
@himat
himat / update_react_state_ex.js
Created December 16, 2020 16:25
[Update element in react state array] #react
// https://stackoverflow.com/a/46761122/1807163
const [employees, setEmployees] = useState([]);
const onUpdate((newEmployee) => {
setEmployees((existingEmployees) => {
const index = employees.findIndex(emp => emp.id === newEmployee.id);
const newEmployees = [...existingEmployees]; // important to create a copy, otherwise you'll modify state outside of setState call
newEemployees[index] = employee;
return newEmployees;
});
@himat
himat / map_option.rs
Created December 16, 2020 19:51
[Extract field inside of optional struct as an option] Use this when you want to extract a field from an optional struct and keep that field also as an option type #rust
struct User {
id: i32,
}
// fn do_something_with_user_id(Option<i32>);
// Bad, simple solution
fn something(user_option: Option<User>) {
let user_id_option = if let Some(user) = user_option { Some(user.id) } else { None };
do_something_with_user_id(user_id_option);
Go to your website of choice in Chrome. e.g.: calendar.google.com
At the top right, click the 3 dots menu
Go to the "More Tools" sub-menu
Click "Create Shortcut"
Give this soon-to-be app a title, and make sure to select "Open as window"
Press Create, and you'll now have an icon in your dock that you can use to open up this page directly and it'll always be in its own window!!