Skip to content

Instantly share code, notes, and snippets.

View mosdevly's full-sized avatar

Mosdev mosdevly

  • San Francisco, CA
View GitHub Profile
if random_choice_index != index_we_are_choosing_for:
# This is a multi-line expression
the_list[index_we_are_choosing_for], the_list[random_choice_index] = \
the_list[random_choice_index], the_list[index_we_are_choosing_for]
# is equivalent to:
the_list[index_we_are_choosing_for], the_list[random_choice_index] = the_list[random_choice_index], the_list[index_we_are_choosing_for]
@mosdevly
mosdevly / git_workflow.sh
Last active July 10, 2018 18:55
Git Workflow
# ALWAYS FORK A REPOSITORY IF YOU'RE WORKING ON THAT PROJECT
# 1. Never work from the main project repo. All devs work from their own forks!
# You should have at least 2 remotes: upstream and origin
# - upstream: the main project repository
# - origin: your fork
# Add a remote
git remote add name_for_your_remote https://github.com/to_your/repository.git
# Example:
@mosdevly
mosdevly / big_o.py
Last active February 13, 2024 20:32
Practice adding any of the missing algorithms. Also beware that there may be logical errors below, but use the comments to help you correct them.
class BigO(object):
"""
Big O Notation by example
Each method below illustrates what algorithms of increasing complexity look like.
"""
from copy import deepcopy
def __init__(self, data_collection):
"""
@mosdevly
mosdevly / resources.md
Created June 20, 2018 18:13
Big O Review -- A discussion of Big O notation and real world application.
@mosdevly
mosdevly / demo.py
Last active June 19, 2018 22:43
Management Commands
# Management commands are easy!
# Following the instructions for getting setup with a management command.
# Here's an example of what that file would look like for seeding a database:
class Command(BaseCommand):
"""
Seeds the database with fake data for demo purposes.
Usage:
@mosdevly
mosdevly / models.py
Last active June 21, 2018 20:47
EC Troubleshooting
class FailureInfo(models.Model):
# Use 'category' instead of type, since thats a keyword in python you don't want to get mixed up!
category = models.CharField(max_length=200)
subtype = models.CharField(max_length=200)
childstep = models.CharField(max_length=200)
owner = models.CharField(max_length=200)
messages = models.CharField(max_length=200)
# Do not use the 'pass' keyword if the class is defined. It's used for objects which aren't defined.
@mosdevly
mosdevly / env.py
Created June 11, 2018 22:33
Using python to retrieve environment variables
# You should add any security credentials to your environment.
# Usualy this means editing shell config files such as .bashrc or .zshrc
# This will retrieve the credential at runtime. It will default to None if no key is found.
# https://docs.python.org/3/library/os.html#os.getenv
import os
SECRET_KEY = os.getenv('KEY_NAME')
require 'rails_helper'
RSpec.describe TodosController, :type => :controller do
describe "GET #index" do
#describe "POST #create" do
#describe "GET #show" do
#describe "PATCH #update" do (or PUT #update)
#describe "DELETE #destroy" do
#describe "GET #new" do
@mosdevly
mosdevly / README.md
Created March 25, 2018 05:07
MEN Stack snippets

These snippets assume the following packages:

  • Mongoose (and therefore MongoDB)
  • Expressjs
  • Passportjs with passport-local
  • Bcrypt

Each snippet can be used wherever you need. Try to understand what they do and how they fit into your app!

@mosdevly
mosdevly / game.js
Created March 10, 2018 09:32
Phaser 2 Game Demo
console.log("Game.js working!");
// Game Jam 2018 Black Girls Code
// http://plnkr.co/edit/xQy9ythXjbdS6WPiYr9P?p=preview
function preload() {
// Needed to load images from imgur
game.load.crossOrigin = "anonymous";
// Preload the sky image
game.load.image("sky", "https://i.imgur.com/ZCWqpAc.png");