Skip to content

Instantly share code, notes, and snippets.

View TimFletcher's full-sized avatar

Tim Fletcher TimFletcher

View GitHub Profile
(ignite)Tim-rMBP:ignite tim$ django-admin.py migrate
Running migrations for longerusernameandemail:
- Migrating forwards to 0001_initial.
> longerusernameandemail:0001_initial
- Loading initial data for longerusernameandemail.
Installed 0 object(s) from 0 fixture(s)
Running migrations for conf:
- Migrating forwards to 0004_ssl_account_settings_rename.
> conf:0001_initial
> conf:0002_auto__add_field_setting_site
@TimFletcher
TimFletcher / gist:bb92b455ce9fd9a7f993
Created December 1, 2015 14:03
Nginx SSL Redirect
# --- Redirect http://respiratoryexam.com and http://www.respiratoryexam.com to https ---
server {
listen 80;
server_name respiratoryexam.com
www.respiratoryexam.com;
return 301 https://respiratoryexam.com$request_uri;
}
# --- Redirect https://www.respiratoryexam.com to http://respiratoryexam.com ---
nylas.drafts.build({
subject: this.email.subject,
body: this.email.html,
to: this.email.to
}).send()
.then(Meteor.bindEnvironment(successCallback))
.catch(Meteor.bindEnvironment(errorCallback));
@TimFletcher
TimFletcher / ternary-array.jsx
Created October 29, 2015 13:15
Returning an array in JSX
{this.showLeadListColumns() ? (
<th className="in-campaign">Campaigns</th>
) : ([
<th className="score">Score</th>,
<th className="page-views">Page Views</th>,
<th className="last-active-at">Last Active</th>
])}
Tim-rMBP:linkmetrics tim$ meteor update
Changes to your project's package version selections from updating the release:
accounts-base upgraded from 1.1.3 to 1.2.0
accounts-google upgraded from 1.0.3 to 1.0.4
accounts-oauth upgraded from 1.1.3 to 1.1.4
accounts-password upgraded from 1.0.6 to 1.1.0
accounts-ui upgraded from 1.1.4 to 1.1.5
accounts-ui-unstyled upgraded from 1.1.6 to 1.1.7
# This works when used in a later query.
user_account_maps = models.UserAccountMap.objects.filter(user_extension__user=user)
account_ids = [uam.account_id for uam in user_account_maps]
# This doesn't
account_ids = models.UserAccountMap.objects.filter(user_extension__user=user).values_list('id', flat=True)
WHAT'S THE DIFFERENCE?
Warning at /dashboard/
# views.py
context = {
contacts: Contacts.objects.some_custom_method.values('id', 'name') # Only allow access to id and name
}
# Pass context to view rendering code
@TimFletcher
TimFletcher / gist:034e799c19eb763fa859
Created August 6, 2014 22:24
Django template filter to add attributes to form fields
# From http://vanderwijk.info/blog/adding-css-classes-formfields-in-django-templates/#comment-1193609278
from django import template
register = template.Library()
@register.filter(name='add_attributes')
def add_attributes(field, css):
attrs = {}
definition = css.split(',')
curl -H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-X POST http://localhost:3000/users \
-d '{"user":{"email":"[email protected]", "password": "123456", "name": "Example User"}}'
require 'yql_finance'
query = YQLFinance::StockQuery.new
response = query.find_by_symbol('P')
results = JSON.parse(response.body)
# To see a nice representation of the hash
pp(results)
# To get LastTradePriceOnly