Skip to content

Instantly share code, notes, and snippets.

View nloadholtes's full-sized avatar
👍
here

Nick Loadholtes nloadholtes

👍
here
View GitHub Profile
@nloadholtes
nloadholtes / login.py
Created August 18, 2015 19:22
Preventing the "remember_token" cookie in flask
login_user(user, remember=False)
Shows = mongoengine.Document()
Movies = mongoengine.Document()
Recommendations = mongoengine.Document()
def front_page(self):
tv_shows = Show.objects.get(genre="comedy")
movies = Movie.objets.get(genre="comedy")
recommendations = Recommendations.objects.get(user_id=current_user)
return render_template("template/front_page.html",
1 - 2015-09-02 07:48:03.367938
2 - 2015-09-02 07:48:03.448904
3 - 2015-09-02 07:48:03.490221
4 - 2015-09-02 07:48:03.490249
5 - 2015-09-02 07:48:10.852490
Shows = mongoengine.Document()
Movies = mongoengine.Document()
Recommendations = mongoengine.Document()
def front_page(self):
print("1 - %s" % datetime.now())
tv_shows = Show.objects.get(genre="comedy")
print("2 - %s" % datetime.now())
movies = Movie.objets.get(genre="comedy")
print("3 - %s" % datetime.now())
1 - 2015-09-02 07:56:21.794712
2 - 2015-09-02 07:56:21.805649
3 - 2015-09-02 07:56:22.984915
4 - 2015-09-02 07:56:22.984987
5 - 2015-09-02 07:56:26.205471
@nloadholtes
nloadholtes / make_some_swap.sh
Created March 13, 2016 01:55
Lets make some swap space!
sudo dd if=/dev/zero of=/swapfile1 bs=1024 count=524288
sudo chown root:root /swapfile1
sudo chmod 0600 /swapfile1
sudo mkswap /swapfile1
sudo swapon /swapfile1
free -m
@nloadholtes
nloadholtes / ijson_example.py
Created March 19, 2016 18:08
An example of using ijson to process streaming JSON in a memory constrained way
#
# This is the core of my handler function
#
batch_size = 100 # This needs to change based on the size of your objects
parser = ijson.parse(f)
counter = 0
to_process = []
for prefix, event, value in parser:
if (prefix, event) == ("item", "start_map"):
music_item = dict(albums=[])
# Step 1, install gunicorn
pip install gunicorn
# Step 2, run it.
gunicorn app:app
class Foo(Model):
class Meta:
# Here, we specify the database and collection names.
# A connection to your DB is automatically created.
database = "minimongo"
collection = "rocks"
foo = Foo.collection.find_one()
fname = foo.first_name
image: node:latest
cache:
paths:
- node_modules/
before_script:
# Install ssh-agent if not already installed, it is required by Docker.
# (change apt-get to yum if you use a CentOS-based image)
- 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )'