Skip to content

Instantly share code, notes, and snippets.

@mo-mughrabi
mo-mughrabi / test_django_admin_pages_listing.py
Last active June 2, 2020 10:56
Testing all admin django list pages
import pytest
from django.conf import settings
from django.urls import URLPattern, URLResolver
def _admin_urls():
""" function to return all admin urls from urlconf.urlpatterns
"""
urlconf = __import__(settings.ROOT_URLCONF, {}, {}, [""])
@syafiqfaiz
syafiqfaiz / how-to-copy-aws-rds-to-local.md
Last active June 22, 2024 20:31
How to copy production database on AWS RDS(postgresql) to local development database.
  1. Change your database RDS instance security group to allow your machine to access it.
    • Add your ip to the security group to acces the instance via Postgres.
  2. Make a copy of the database using pg_dump
    • $ pg_dump -h <public dns> -U <my username> -f <name of dump file .sql> <name of my database>
    • you will be asked for postgressql password.
    • a dump file(.sql) will be created
  3. Restore that dump file to your local database.
    • but you might need to drop the database and create it first
    • $ psql -U <postgresql username> -d <database name> -f <dump file that you want to restore>
  • the database is restored
@pgporada
pgporada / Makefile
Last active August 16, 2022 08:33
Terraform Makefile
.ONESHELL:
.PHONEY: help set-env init update plan plan-destroy show graph apply output taint
help:
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
set-env:
@if [ -z $(ENVIRONMENT) ]; then\
echo "ENVIRONMENT was not set"; exit 10;\
fi
import logging
import subprocess
import salt.utils
log = logging.getLogger(__name__)
def primary_interface():
try:
import salt.utils.network as network
except Exception as e:
node {
// https://registry.hub.docker.com/_/maven/
def maven32 = docker.image('maven:3.2-jdk-7-onbuild');
stage 'Mirror'
// First make sure the slave has this image.
// (If you could set your registry below to mirror Docker Hub,
// this would be unnecessary as maven32.inside would pull the image.)
maven32.pull()
// We are pushing to a private secure docker registry in this demo.
@stuart-warren
stuart-warren / CreateJob.sh
Last active March 8, 2024 16:20
Create a job in Jenkins (or folder) using the HTTP API
# check if job exists
curl -XGET 'http://jenkins/checkJobName?value=yourJobFolderName' --user user.name:YourAPIToken
# with folder plugin
curl -s -XPOST 'http://jenkins/job/FolderName/createItem?name=yourJobName' --data-binary @config.xml -H "Content-Type:text/xml" --user user.name:YourAPIToken
# without folder plugin
curl -s -XPOST 'http://jenkins/createItem?name=yourJobName' --data-binary @config.xml -H "Content-Type:text/xml" --user user.name:YourAPIToken
# create folder
@insin
insin / submitthenscrape.py
Created December 12, 2011 21:35
Scrapy - submit form to set up cookies, then scrape known URLs...
from scrapy.http import FormRequest, Request
from scrapy.selector import HtmlXPathSelector
from scrapy.spider import BaseSpider
BASE_URL = 'http://www.url.com/'
class ThingSpider(BaseSpider):
name = 'thing'
start_urls = ['%ssearchThing.php' % BASE_URL]
@vstoykov
vstoykov / force_default_language_middleware.py
Last active June 6, 2024 10:51
Force Django to use settings.LANGUAGE_CODE for default language instead of request.META['HTTP_ACCEPT_LANGUAGE']
try:
from django.utils.deprecation import MiddlewareMixin
except ImportError:
MiddlewareMixin = object
class ForceDefaultLanguageMiddleware(MiddlewareMixin):
"""
Ignore Accept-Language HTTP headers