Skip to content

Instantly share code, notes, and snippets.

View etiennepouliot's full-sized avatar

Etienne Pouliot etiennepouliot

View GitHub Profile
@rfennell
rfennell / AZDO-StageDependencyVariables.yml
Last active June 10, 2024 01:27
Azure DevOps Pipelines Stage Dependency Variables Usage Demo
parameters:
- name: Value
type: boolean
default: true
pool:
vmImage: ubuntu-latest
stages:
@zanechua
zanechua / azure-pipelines.yml
Last active April 11, 2023 11:51
Azure Pipeline + Laravel + MySQL + PHPUnit + Laravel Dusk
# PHP
# Test and package your PHP project.
# Add steps that run tests, save build artifacts, deploy, and more:
# https://docs.microsoft.com/azure/devops/pipelines/languages/php
pool:
vmImage: 'Ubuntu 16.04'
variables:
phpVersion: 7.2
@maurobaraldi
maurobaraldi / tests.py
Created May 24, 2016 17:53
Django unittest view with mock
from django.test import Client, TestCase
from mock import patch
from .views import index
class SimpleTestCase(TestCase):
def setUp(self):
self.client = Client()
@patch('api.views.requests')
@benbacardi
benbacardi / gist:227f924ec1d9bedd242b
Last active May 12, 2024 09:55
Django reverse with a querystring
from django.utils.http import urlencode
def reverse_querystring(view, urlconf=None, args=None, kwargs=None, current_app=None, query_kwargs=None):
'''Custom reverse to handle query strings.
Usage:
reverse('app.views.my_view', kwargs={'pk': 123}, query_kwargs={'search': 'Bob'})
'''
base_url = reverse(view, urlconf=urlconf, args=args, kwargs=kwargs, current_app=current_app)
if query_kwargs:
return '{}?{}'.format(base_url, urlencode(query_kwargs))
@Jaykul
Jaykul / ProxyForwarder.ps1
Created March 20, 2015 06:43
PowerShell NetMQ
# Set up the proxy forwarder ...
Add-Type -path .\NetMQ\lib\net40\NetMQ.dll
Start-Job {
try {
$context = [NetMQ.NetMQContext]::Create()
$publisher = $context.CreateXPublisherSocket()
$subscriber = $context.CreateXSubscriberSocket()
$publisher.Bind("tcp://127.0.0.1:50007");
@mattlong
mattlong / admin.py
Created September 17, 2014 18:26
Add a custom admin page for a model and link to it from the detail page
from functools import update_wrapper
from django.contrib import admin
from django.contrib.admin import ModelAdmin
from django.contrib.admin.templatetags.admin_urls import add_preserved_filters
from django.core.exceptions import PermissionDenied
from django.shortcuts import render
from myapp.models import Widget
from myapp.forms import ManageWidgetForm
@cansadadeserfeliz
cansadadeserfeliz / forms.py
Created June 19, 2014 20:35
Django: pass a variable from a form view to a form
class MyForm(forms.ModelForm):
requested_asset = None
def __init__(self, *args, **kwargs):
other_variable = kwargs.pop('other_variable')
super(MyForm, self).__init__(*args, **kwargs)
@mangecoeur
mangecoeur / concurrent.futures-intro.md
Last active January 9, 2024 16:04
Easy parallel python with concurrent.futures

Easy parallel python with concurrent.futures

As of version 3.3, python includes the very promising concurrent.futures module, with elegant context managers for running tasks concurrently. Thanks to the simple and consistent interface you can use both threads and processes with minimal effort.

For most CPU bound tasks - anything that is heavy number crunching - you want your program to use all the CPUs in your PC. The simplest way to get a CPU bound task to run in parallel is to use the ProcessPoolExecutor, which will create enough sub-processes to keep all your CPUs busy.

We use the context manager thusly:

with concurrent.futures.ProcessPoolExecutor() as executor:
@dantheautomator
dantheautomator / logstash filter for nxlog json
Last active October 2, 2019 17:30
Using nxlog to rename fields to match logstash syslog input. Yes, I could have just sent the raw message to the logstash syslog input, but this taught me a lot about nxlog and some of this is not well documented.
filter {
if [nxtags] == "nxlogsyslog" {
mutate {
add_field => [ "type", "%{nxtags}" ]
replace => [ "host", "%{Hostname}" ]
}
# Parse the date 2014-02-27 14:57:04 - Needed to set timezone value to nxlog server's timezone
date {
@cha55son
cha55son / dynmotd
Last active June 9, 2023 21:06
RHEL (Centos/Fedora) dynamic motd
#!/bin/bash
# Installation:
#
# 1. vim /etc/ssh/sshd_config
# PrintMotd no
#
# 2. vim /etc/pam.d/login
# # session optional pam_motd.so
#