npm install --save-dev jest ts-jest jest-environment-jsdom @testing-library/react @testing-library/react-hooks @testing-library/user-event @testing-library/jest-dom
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default function SessionsList() { | |
const sessionsQuery = useSessionsListQuery(); | |
return ( | |
<PageLayout title="My sessions"> | |
{matchQueryStatus(sessionsQuery, { | |
Loading: ( | |
<> | |
<Skeleton height={70} mt={6} /> | |
<Skeleton height={70} mt={6} /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function gitlabcilint() { | |
data=$(cat .gitlab-ci.yml | node -e 'fs=require("fs");console.log(JSON.stringify({content:fs.readFileSync(0,"utf8")}))') | |
curl --header "Content-Type: application/json" https://gitlab.com/api/v4/ci/lint --data "${data}" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from rest_framework.views import exception_handler | |
from rest_framework.exceptions import ErrorDetail, _get_full_details | |
def custom_exception_handler(exc, context): | |
# Call REST framework's default exception handler first, | |
# to get the standard error response. | |
response = exception_handler(exc, context) | |
# Now add the HTTP status code to the response. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
u = User.objects.get(username=username) | |
from rest_framework.test import APIRequestFactory, force_authenticate | |
factory = APIRequestFactory() | |
request = factory.get(url, format='json') | |
force_authenticate(request, u) | |
view = MyView.as_view() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# frozen_string_literal: true | |
# To use with a ActiveRecord array column for instance: | |
# add_column :myobjects, :features, :integer, array: true, default: [] | |
# | |
# Based on https://tenforward.consulting/blog/integrating-an-array-column-in-rails-with-simple-form | |
class ArraySelectInput < SimpleForm::Inputs::CollectionSelectInput | |
def input(wrapper_options = nil) | |
label_method, value_method = detect_collection_methods |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
import urllib | |
ALLOWED_HOSTS = ["localhost", "127.0.0.1"] | |
# Try to find a runnning ngrok instance | |
try: | |
tunnels = requests.get('http://127.0.0.1:4040/api/tunnels') | |
url = tunnels.json()['tunnels'][0]['public_url'] | |
ngrok_domain = urllib.parse.urlparse(url).netloc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
return data.map((value, index) => {return index + '=' + value)).join('&'); |