Skip to content

Instantly share code, notes, and snippets.

@hirobert
hirobert / response-content-disposition-cloudfront.txt
Last active December 21, 2023 20:38
response-content-disposition and cloudfront
1) Log in to aws console.
2) Click cloudfront
3) Click behaviors
4) Select pattern and edit
@jhgaylor
jhgaylor / through_relationships.py
Last active December 20, 2023 09:49
Example of using a through model in Django and filtering by a value on the custom through model.
class A(models.Model):
things = models.ManyToManyField("B", through=ThroughModel)
class B(models.Model):
text = models.TextField()
class ThroughModel(models.Model):
a = models.ForeignKey(A)
b = models.ForeignKey(B)
extra = models.BooleanField()
@thiagomarini
thiagomarini / readme.sh
Created October 29, 2018 16:10
How to install supervisor on Amazon Linux
# Install it as a yum package instead of throgh pip (will save you from lots of hassle)
# first get epel
sudo amazon-linux-extras install epel
# then install supervisor
sudo yum install supervisor
@davidrushton
davidrushton / Kernel.php
Created February 17, 2016 17:29
Laravel 5 Database Queue - Shared Hosting
<?php
namespace App\Console;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
class Kernel extends ConsoleKernel
{
/**
@mauris
mauris / queue-ensure.php
Created April 28, 2014 15:44
Laravel Artisan Queue Ensurer - Set a cron job to run this file periodically to ensure that Laravel's queue is processing all the time. If the queue listener stopped, restart it!
<?php
function runCommand ()
{
$command = 'php artisan queue:listen > /dev/null & echo $!';
$number = exec($command);
file_put_contents(__DIR__ . '/queue.pid', $number);
}
if (file_exists(__DIR__ . '/queue.pid')) {
@mbrochh
mbrochh / 01_utils.py
Last active September 24, 2023 10:45
Using pagination with Django, graphene and Apollo
from django.core.paginator import EmptyPage, PageNotAnInteger, Paginator
# First we create a little helper function, becase we will potentially have many PaginatedTypes
# and we will potentially want to turn many querysets into paginated results:
def get_paginator(qs, page_size, page, paginated_type, **kwargs):
p = Paginator(qs, page_size)
try:
page_obj = p.page(page)
except PageNotAnInteger:
@krambertech
krambertech / Component.jsx
Created July 2, 2016 10:44
ReactJS: Input fire onChange when user stopped typing (or pressed Enter key)
import React, { Component } from 'react';
import TextField from 'components/base/TextField';
const WAIT_INTERVAL = 1000;
const ENTER_KEY = 13;
export default class TextSearch extends Component {
constructor(props) {
super();
@ARolek
ARolek / ImageMagick-Amazon-Linux.md
Last active February 10, 2023 00:07
Install ImageMagick from source on Amazon Linux

I needed a newer version of ImageMagick than is available on the yum packages on Amazon Linux. I tried using the remi repo but it failed with dependency errors. Here is what I did to install ImageMagick with support for PNG, JPG, and TIFF.

download the most recent package

wget http://www.imagemagick.org/download/ImageMagick.tar.gz

uncomress the package

@ibrahimlawal
ibrahimlawal / verify-and-handle-paystack-event.php
Last active June 22, 2022 22:17
Paystack Webhook Code Skeleton, PHP
<?php
if ((strtoupper($_SERVER['REQUEST_METHOD']) != 'POST' ) || !array_key_exists('HTTP_X_PAYSTACK_SIGNATURE', $_SERVER) ) {
// only a post with paystack signature header gets our attention
exit();
}
// Retrieve the request's body
$input = @file_get_contents("php://input");
define('PAYSTACK_SECRET_KEY','sk_xxxx_xxxxxx');
@ibrahimlawal
ibrahimlawal / paystack-transaction-initialize.php
Last active December 17, 2020 13:54
Initializing a Paystack Transaction for 20 naira // And verifying it. // Uses Paystack Class : https://github.com/yabacon/paystack-class
<?php
// Get this from https://github.com/yabacon/paystack-class
require 'Paystack.php';
$paystack = new Paystack('sk_test_xxx');
// the code below throws an exception if there was a problem completing the request,
// else returns an object created from the json response
$trx = $paystack->transaction->initialize(