Skip to content

Instantly share code, notes, and snippets.

View mosdevly's full-sized avatar

Mosdev mosdevly

  • San Francisco, CA
View GitHub Profile
@mosdevly
mosdevly / binary_search.py
Created March 10, 2018 04:41
Binary Search in Python
# iterative implementation of binary search in Python
def binary_search(a_list, item):
"""Performs iterative binary search to find the position of an integer in a given, sorted, list.
a_list -- sorted list of integers
item -- integer you are searching for the position of
"""
@mosdevly
mosdevly / models_Todo.js
Created March 8, 2018 19:24
Intro to Mongo code-a-long code
// models/Todo.js
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var TodoSchema = new Schema({
name: String
});
var Todo = mongoose.model('Todo', TodoSchema);
@mosdevly
mosdevly / solution.rb
Created November 30, 2017 15:59
Cats in hats algorithm
# See the comments below the solution for some tips on thinking about the problem.
# You can test each line of code in your Ruby interpreter!
def how_many_cats_with_hats?
cats = {}
(1..100).each { |i| cats[i] = false }
(1..100).each do |n|
cats.each_key do |cat|
if (cat % n).zero?
@mosdevly
mosdevly / app.yaml
Created September 4, 2017 19:32
Google Cloud Config
runtime: python27
version: 1
threadsafe: true
handlers:
- url: /*
- script: trashtalk.app
@mosdevly
mosdevly / util.py
Created March 25, 2017 19:47 — forked from kgriffs/util.py
Deprecated decorator for Python. Uses clever introspection to set a helpful filename and lineno in the warning message.
import functools
import inspect
import warnings
# NOTE(kgriffs): We don't want our deprecations to be ignored by default,
# so create our own type.
class DeprecatedWarning(UserWarning):
pass
@mosdevly
mosdevly / deprecated.py
Created March 25, 2017 19:45 — forked from Xion/deprecated.py
@deprecated decorator for Python classes
import functools
import inspect
import os
import warnings
class _DeprecatedDecorator(object):
MESSAGE = "%s is @deprecated"
def __call__(self, symbol):
@mosdevly
mosdevly / beautiful_idiomatic_python.md
Created February 18, 2017 06:09 — forked from JeffPaine/beautiful_idiomatic_python.md
Transforming Code into Beautiful, Idiomatic Python: notes from Raymond Hettinger's talk at pycon US 2013. The code examples and direct quotes are all from Raymond's talk. I've reproduced them here for my own edification and the hopes that others will find them as handy as I have!

Transforming Code into Beautiful, Idiomatic Python

Notes from Raymond Hettinger's talk at pycon US 2013 video, slides.

The code examples and direct quotes are all from Raymond's talk. I've reproduced them here for my own edification and the hopes that others will find them as handy as I have!

Looping over a range of numbers

for i in [0, 1, 2, 3, 4, 5]:
@mosdevly
mosdevly / serializers1.py
Last active January 20, 2017 02:45
Review of Serializers
"""
Some info to help!
Ideally we really want to use the CustomerLoanProfileV1Serializer. But that means rearranging the order of classes in the file or using
separate files. It would further be a good idea to consider adding serializers to the loans app so that other apps could use it.
I've added some comments and docstrings below. Please also add your own if you feel inclined. We can merge your documentation updates so
that it helps us all!
"""
@mosdevly
mosdevly / inclass.py
Last active January 18, 2017 04:40
ClassPass
"""
Broadly Classroom Analyzer Script
Class is defined as: each object that contains students. This includes
the 'next' links which are assumed to be additional sessions for the same
class type. In other words, 'next' links are treated as their own class.
"""
from multiprocessing.dummy import Pool as ThreadPool
import urllib3
@mosdevly
mosdevly / sshconfig
Created December 11, 2016 18:56
SSH Config Example
# Format
Host alias
HostName myserver.com
User username
IdentityFile ~/.ssh/mykey
# Usage: `ssh alias`
# Alternative: `ssh -i ~/.ssh/mykey username@myserver.com`
Host myrepos
HostName github.com