Skip to content

Instantly share code, notes, and snippets.

View cstrap's full-sized avatar
🐍

Christian Strappazzon cstrap

🐍
View GitHub Profile
@mixxorz
mixxorz / services.py
Last active January 21, 2020 16:52
Django Service Objects
from django import forms
from django.core.exceptions import ValidationError
from django.db import transaction
class InvalidInputsError(Exception):
def __init__(self, errors, non_field_errors):
self.errors = errors
self.non_field_errors = non_field_errors
@tuxskar
tuxskar / packtpub_get_your_library_books.js
Last active July 23, 2019 15:06 — forked from juzim/packtpub_get_dl_links.js
Create wget commands for all claimed books on packtpub
/*
== Adapted from the code over at https://gist.github.com/graymouser/a33fbb75f94f08af7e36 ==
Log into your account at packtpub.com and save the cookies with the "cookies.txt" Chrome extension or the "Export cookies" Firefox extension into the file cookies.txt.
Then open the console in your browsers dev tools and paste the following code.
You will get a list of wget commands that you can copy and paste as a whole into a terminal to download all books.
Example: wget --load-cookies=cookies.txt --content-disposition "https://packtpub.com//ebook_download/20217/mobi" -O "R Data Visualization Cookbook.mobi"
If you only want some filetypes, edit the "pattern" vaiable accordingly.
@eldondevcg
eldondevcg / README.md
Last active November 18, 2020 10:31
Cross account bucket access for IAM roles

For: https://www.reddit.com/r/aws/comments/5jf7fb/permissions_for_lambda_accessing_s3_buckets_in/

This is a little tricky, because it requires several different moving parts, specifically,

  • the lambda task that you want to execute the copy must have IAM access to the bucket in the other account. This is not something that was obvious to me to begin with, although my use case was more complicated.
  • the bucket policy on the destination account must be set to permit your lambda function to write to that bucket. For my special use cases, I have to upload a new bucket policy daily to the receiving buckets. Alternatively, the destination accounts could probably give your a cross-account IAM role to upload the bucket policy yourself.
  • You will likely want to write your objects with the bucket-owner-full-control acl, http://docs.aws.amazon.com/AmazonS3/latest/dev/acl-overview.html otherwise, the bucket owner may not be able to download them.
import sys, marshal, functools, subprocess
child_script = """
import marshal, sys, types;
fn, args, kwargs = marshal.load(sys.stdin)
marshal.dump(
types.FunctionType(fn, globals())(*args, **kwargs),
sys.stdout)
"""
@gabrielelana
gabrielelana / Vagrantfile
Last active January 2, 2024 18:58
How to create a VirtualBox machine with encrypted storage with Vagrant
# -*- mode: ruby -*-
# vi: set ft=ruby :
PASSWORD_PATH = ".password"
PASSWORD_ID_PATH = ".password_id"
# Make sure to have installed vagrant-triggers plugin
# > vagrant plugin install vagrant-triggers
# After the first `vagrant up` stop the VM and execute the following steps
@frague59
frague59 / search.py
Created November 6, 2015 09:03
search features with attachment supports
# -*- coding: utf-8 -*-
"""
Search features for an elasticsearch / haystack / elasticstack
:creationdate: 05/11/15 15:05
:moduleauthor: François GUÉRIN <fguerin@ville-tourcoing.fr>
:modulename: intrautils.search
"""
import base64
@adamwathan
adamwathan / v-cloak.md
Last active February 26, 2023 14:26
Useful CSS utilities for Vue.js cloaking

Handy helpers for controlling visibility of elements until Vue has compiled.

Use like:

<div v-cloak>
  <h1>
    <span class="v-cloak--inline">Loading...</span> <!-- Only displayed before compiling -->
    <span class="v-cloak--hidden">{{ post.title }}</span> <!-- Hidden until compiling is finished -->
 
import haystack
from django.core.management import call_command
from django.test.utils import override_settings
TEST_INDEX = {
'default': {
'ENGINE': 'haystack.backends.elasticsearch_backend.ElasticsearchSearchEngine',
'URL': 'http://127.0.0.1:9200/',
@soheilhy
soheilhy / nginxproxy.md
Last active May 16, 2024 08:59
How to proxy web apps using nginx?

Virtual Hosts on nginx (CSC309)

When hosting our web applications, we often have one public IP address (i.e., an IP address visible to the outside world) using which we want to host multiple web apps. For example, one may wants to host three different web apps respectively for example1.com, example2.com, and example1.com/images on the same machine using a single IP address.

How can we do that? Well, the good news is Internet browsers

@ushu
ushu / S3 buckets copy.md
Created October 29, 2013 16:12
Copy between S3 buckets w/ different accounts

This is a mix between two sources:

basically the first resource is great but didn't work for me: I had to remove the trailing "/*" in the resource string to make it work. I also noticed that setting the policy on the source bucket was sufficient. In the end these are the exact steps I followed to copy data between two buckets on two accounts

Basically the idea there is:

  • we allowe the destination account to read the source bucket (in the console for the source account)
  • we log as the destination and start the copy