Skip to content

Instantly share code, notes, and snippets.

View jorgeas80's full-sized avatar
🎯
Focusing

Jorge Arévalo jorgeas80

🎯
Focusing
View GitHub Profile
@joyrexus
joyrexus / README.md
Last active June 8, 2023 07:45
form-data vs -urlencoded

Nice answer on stackoverflow to the question of when to use one or the other content-types for POSTing data, viz. application/x-www-form-urlencoded and multipart/form-data.

“The moral of the story is, if you have binary (non-alphanumeric) data (or a significantly sized payload) to transmit, use multipart/form-data. Otherwise, use application/x-www-form-urlencoded.”


Matt Bridges' answer in full:

The MIME types you mention are the two Content-Type headers for HTTP POST requests that user-agents (browsers) must support. The purpose of both of those types of requests is to send a list of name/value pairs to the server. Depending on the type and amount of data being transmitted, one of the methods will be more efficient than the other. To understand why, you have to look at what each is doing

@jayapal
jayapal / gist:93f783d3550eaf1555ab
Created March 22, 2015 16:53
Django listview as JSON and Jquery getJSON example
class JsonResponseMixin(object):
"""
Return json
"""
def render_to_response(self, context):
queryset = self.model.objects.all()
data = serializers.serialize('json', queryset)
return HttpResponse(data, content_type='application/json')
JSON parsing using getJSON
@za
za / tests.py
Last active June 27, 2018 17:09
django-testing: mock datetime.datetime.now()
import mock
from django.test import TestCase, Client
import datetime
class StubDate(datetime.datetime):
pass
class TestApp(TestCase):
@mock.patch('app.views.datetime.datetime', StubDate) #app is the $django_application_name
@cerebrl
cerebrl / es6-features.md
Last active July 29, 2024 13:13
Interesting ES6 features
@slinkp
slinkp / gist:c3ec1f47d7ecfe682ad4
Last active August 10, 2023 10:11
How to use Mock Specs Properly with Classes
"""
TL/DR:
Never instantiate mock.Mock() directly.
Instead use either mock.create_autospec(YourClass) OR mock.patch('YourClass', autospec=True).
The "spec" feature of Mock is great, it helps avoid your mocked API drifting out of sync with your real API.
But there is a gotcha if you are mocking classes directly - it's easy to mock the class but you need to
ensure the spec applies to the *instance* as well.
"""
@amatellanes
amatellanes / celery.sh
Last active April 28, 2025 03:31
Celery handy commands
/* Useful celery config.
app = Celery('tasks',
broker='redis://localhost:6379',
backend='redis://localhost:6379')
app.conf.update(
CELERY_TASK_RESULT_EXPIRES=3600,
CELERY_QUEUES=(
Queue('default', routing_key='tasks.#'),
@feryardiant
feryardiant / dmg2img.md
Created July 29, 2014 00:36
Create bootable USB from .DMG image file in Linux

Create bootable USB from .DMG image file in Linux

Courtesy: [email protected]

Install dmg2img

$ sudo apt-get install dmg2img
@Kartones
Kartones / postgres-cheatsheet.md
Last active June 18, 2025 16:41
PostgreSQL command line cheatsheet

PSQL

Magic words:

psql -U postgres

Some interesting flags (to see all, use -h or --help depending on your psql version):

  • -E: will describe the underlaying queries of the \ commands (cool for learning!)
  • -l: psql will list all databases and then exit (useful if the user you connect with doesn't has a default database, like at AWS RDS)
@paambaati
paambaati / upload_demo_html.html
Last active March 28, 2021 14:55
Uploading files using NodeJS and Express 4
<html>
<body>
<form action="/upload" enctype="multipart/form-data" method="post">
<input type="text" name="title">
<input type="file" name="file">
<input type="submit" value="Upload">
</form>
</body>
</html>