Skip to content

Instantly share code, notes, and snippets.

@mbrochh
mbrochh / demo.py
Last active May 5, 2020 02:38
Validating a Django model instance with a model form without having a form data dict
# We have many instances in our apps where the user goes through many steps of forms.
# Each step obviously has it's own ModelForm. At the end, there is usually a final step
# for the user to submit everything. For this step, we usually want to run all the other
# form validations again, just to be sure that all the data looks good.
# Problem: How do you run a form validation if you don't have any POST/GET data?
class Form1(forms.ModelForm):
class Meta:
model = Model1
@mbrochh
mbrochh / .bashrc
Last active February 28, 2020 15:48
.bashrc with pyenv-virtualenvwrapper
if command -v pyenv 1>/dev/null 2>&1; then
eval "$(pyenv init -)"
fi
export PYENV_VIRTUALENVWRAPPER_PREFER_PYVENV="true"
export WORKON_HOME=$HOME/.virtualenvs
pyenv virtualenvwrapper_lazy

Keybase proof

I hereby claim:

  • I am mbrochh on github.
  • I am mbrochh (https://keybase.io/mbrochh) on keybase.
  • I have a public key ASDTuzhLkQ2LcfTUBN6bQ2WvvX2c7kduUqWgL5sUuidzYgo

To claim this, I am signing this object:

### Keybase proof
I hereby claim:
* I am mbrochh on github.
* I am mbrochh (https://keybase.io/mbrochh) on keybase.
* I have a public key ASDTuzhLkQ2LcfTUBN6bQ2WvvX2c7kduUqWgL5sUuidzYgo
To claim this, I am signing this object:
@mbrochh
mbrochh / 01_dont_do_this.js
Last active July 4, 2018 09:15
Issue with react-loadable, react-router and react-apollo when loading the same component twice.
// Kudos to @kronosfere for discovering this!!
// App.js:
const SomeView = Loadable({
loader: () => import('./SomeView.js'),
loading: Loading,
})
const SomeWrapperView = Loadable({
@mbrochh
mbrochh / some_test.js
Last active February 8, 2024 13:02
Controlling a Stripe payent popup with Cypress.io
// for this to work you need to set `"chromeWebSecurity": false` in cypress.json
describe('Make Stripe Payment', function() {
before(function() {
cy.visit('http://localhost:3000/en/stripe/checkout/')
Cypress.Cookies.preserveOnce('sessionid')
})
it('should enter credit card details and finalise payment', function() {
cy.get('[data-test="button-FormStripeCart-PayWithCreditCard"]').click()
@mbrochh
mbrochh / 01_utils.py
Last active September 24, 2023 10:45
Using pagination with Django, graphene and Apollo
from django.core.paginator import EmptyPage, PageNotAnInteger, Paginator
# First we create a little helper function, becase we will potentially have many PaginatedTypes
# and we will potentially want to turn many querysets into paginated results:
def get_paginator(qs, page_size, page, paginated_type, **kwargs):
p = Paginator(qs, page_size)
try:
page_obj = p.page(page)
except PageNotAnInteger:
@mbrochh
mbrochh / gist:273a16241eaa414aca595e4c50812582
Created June 8, 2016 23:03
Verifying that +mbrochh is my blockchain ID. https://onename.com/mbrochh
Verifying that +mbrochh is my blockchain ID. https://onename.com/mbrochh
@mbrochh
mbrochh / component.jsx
Created May 6, 2016 11:49
ReactJS propTypes composition
class Component1 extends React.Component {
static propTypes = {
some: React.PropTypes.bool,
prop: React.PropTypes.string,
types: React.PropTypes.object,
}
}
class Component2 extends React.Component {
static propTypes = {
@mbrochh
mbrochh / graphiql
Created May 4, 2016 04:47
GraphQL Schema
query {
products {
id
}
}