Skip to content

Instantly share code, notes, and snippets.

View amites's full-sized avatar

Alvin Mites amites

View GitHub Profile
@amites
amites / evernote-morning-page.scpt
Created November 4, 2020 03:00
Applescript to create a "morning pages" journal prompt in evernote
(*
Evernote Morning Page
VERSION 1.0
September 10, 2019
USAGE:
Save with Script Editor
then open a terminal
run `crontab -e`
add entry `# * 6 * * * osascript ~/Downloads/evernote-morning-page.scpt`
@amites
amites / PROJECT.service
Created April 25, 2019 14:59
Nginx & Gunicorn Boilerplate Config
[Unit]
Description=Gunicorn PROJECTNAME Daemon
After=network.target
[Service]
User=VALIDUSER
Group=www-data
WorkingDirectory=/PATH/TO/PROJECT/ROOT
ExecStart=/PATH/TO/GUNICORN/bin/gunicorn --workers 3 --bind unix:/PATH/TO/PROJECT/ROOT/PROJECTNAME.sock PROJECTDIR.wsgi:application
[Install]
fundweb_1 | fail: Microsoft.EntityFrameworkCore.Update[10000]
fundweb_1 | An exception occurred in the database while saving changes for context type 'FundWeb.Data.FundWebContext'.
fundweb_1 | System.InvalidOperationException: A second operation started on this context before a previous operation completed. Any instance members are not guaranteed to be thread safe.
fundweb_1 | at Microsoft.EntityFrameworkCore.Internal.ConcurrencyDetector.EnterCriticalSection()
fundweb_1 | at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.<SaveChangesAsync>d__61.MoveNext()
fundweb_1 | --- End of stack trace from previous location where exception was thrown ---
fundweb_1 | at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
fundweb_1 | at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
fundweb_1 | at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
fundweb_1 |
@amites
amites / attr_wtf.py
Created February 24, 2017 22:12
Why do I get a different result from `getattr` and a direct attribute call?
# function being called
# Use case is within a migration
# apps = `from django.apps import apps` -- within a migration
# model_name = str lowercase model name
def blob_to_file(apps, model_name, text_field_name, file_field_name):
"""
Upload existing TextField json blobs to files.
"""
@amites
amites / installfest.md
Last active November 16, 2016 13:50
Installfest 1

Welcome to Introduction to Python Programming

If you are unable or uncomfortable with installing programs to your computer you can use the following web-site. It will be fully functional for this bootcamp but will not provide some useful shortcuts.

OSX / Linux

  • Python is already installed -- =)

  • Install easy_install

@amites
amites / unit_test_exmple.py
Created October 30, 2016 05:30
Python unit testing example.
import unittest
class TestStringMethods(unittest.TestCase):
def test_upper(self):
self.assertEqual('foo'.upper(), 'FOO')
def test_isupper(self):
self.assertTrue('FOO'.isupper())
self.assertFalse('Foo'.isupper())
@amites
amites / README-class-18.md
Created September 19, 2016 22:23
Extending Django project hello_world with the admin, views and extending models.

This section will continue from our Davinci Django project.

First we'll update our existing models to include additional fields.

Open hello_world/models.py and add 2 fields to StuffToRate

ex:

	color = models.CharField(max_length=100, default='Green')
	description = models.TextField()
@amites
amites / setup_django_project.md
Last active September 19, 2016 16:31
README to setup a new django project.

In Terminal run the following commands

    virtualenv  VIRTUALENV_NAME
    cd VIRTUALENV_NAME
    source bin/activate
    pip install django ipython
@amites
amites / camel_case.py
Created September 10, 2016 16:28
Camel Case Code Wars
# https://www.codewars.com/kata/convert-string-to-camel-case/train/python
def to_camel_case(text):
text_list = text.replace('-', '_').split('_')
answer_list = [text_list[0], ]
for word in text_list[1:]:
answer_list.append( word.title() )
return ''.join(answer_list)
# solution to entry problem 1
def multiply(a, b):
return a * b
# solution to entry problem 2
class Person:
def __init__(self, name):
self.name = name