Skip to content

Instantly share code, notes, and snippets.

View fodra's full-sized avatar
🎯
Focusing

Andrew Artajos fodra

🎯
Focusing
  • Australia
View GitHub Profile
@fodra
fodra / GitStuff.md
Last active May 30, 2018 04:50
Git commands
  1. Remove all untracked git files

$ git clean -fd

  1. View all tags

$ git tag

  1. Undo last commit
@fodra
fodra / snippets.js
Created May 11, 2018 04:33
Useful snippets of js code
// sleep using promise
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
@fodra
fodra / DjangoRelationships.md
Created April 18, 2018 01:21
Django Relationship notes.
  1. One-to-Many or Many-to-One relationships
  • One gets no field
  • Many gets the ForeignKey field
class One(models.Model):
  pass
  
class Many(models.Model):
@fodra
fodra / Postgres.md
Last active June 20, 2018 07:42
Notes on postgres database
  1. Create a copy of a database

$ createdb -O <owner> -T database_to_copy new_database

  1. Create a database

$ createdb -O <owner> database_name

@fodra
fodra / Django.md
Last active May 31, 2018 04:55
Notes on Django
  1. Create an empty django migration

python manage.py makemigrations --empty yourappname

  1. Show applied migrations

python manage.py showmigrations <app_name>

  1. Rollback migration to a specific state
@fodra
fodra / Makefile
Created March 28, 2018 22:42
A sample makefile
# Shortcuts for doing stuff in gametraka_project_v3
.PHONY : clean help build redisq gui devdeps dev clean run requirements test
help:
@echo "lint - check style with flake8 and isort"
@echo "devdeps - runs rqworker and gui front-end"
@echo "dev - runs gametraka on localhost"
@echo "test - runs test suite"
@echo "clean - deletes temporary files"
-- get the 10 most recent sold listings for the specific agency
SELECT id, status, sold_price, sold_date
FROM listings_listing
WHERE agency_id = '3ab9adc2-7fd2-4b24-8cd0-d0cc69270fbf' AND status = 'S'
ORDER BY sold_date DESC LIMIT 10;
-- modify the query set to a new date somewhere between now and four weeks ago
UPDATE listings_listing
SET sold_date = now(),
source_type = 'M'
@fodra
fodra / pgexercises-joins-notes.md
Created February 7, 2018 11:26
All about joins in PostgreSQL.

Joins

Retrieve the start times of members' bookings

The main thing here is the bit where you rename the table to something shorter: cd.members > mem. However this site clearly doesn't do that.

The concept is simple enough, you just have to join two tables that are related via a foreign key. When you join them together, you get a more detailed row.

@fodra
fodra / pgexercises-basic-notes.md
Last active February 20, 2018 11:28
Here are some of my notes to the answers in pgexercises

Basic

Retrieve everything from a table

select * from cd.facilities;

Retrieve specific columns from the table

select name, membercost from cd.facilities;

@fodra
fodra / deep_copy.js
Created January 26, 2018 11:55
This is how you perform a deep copy in javascript as discussed in the HN article: Deep-copying in JavaScript.
function deepCopy(obj) {
return new Promise(resolve => {
const {send, recv} = new MessageChannel();
recv.onmessage = ev => resolve(ev.data);
send.postMessage(obj);
});
}
const obj = /* object to copy */;
const clone = await deepCopy(obj);