Skip to content

Instantly share code, notes, and snippets.

View IhateTrains's full-sized avatar

IhateTrains

  • Rzeszow University of Technology
  • Poland
View GitHub Profile
@henhan
henhan / nginx_documentation.md
Last active June 27, 2024 16:47
Extend and override nginx config for Elastic Beanstalk Amazon Linux 2

Extend and override nginx config for Elastic Beanstalk Amazon Linux 2

Documentation on how to override or extend the default nginx config on Elastic Beanstalk running om Amazon Linux 2. Correct as of 2021-08-01. Also see the general documentation on how to extend linux servers.

All references to placing files refer to putting a file at this location in your application bundle. You should never modify a file directly at your Elastic Beanstalk server by ssh:ing to the server, since such a change will be wiped whenever your servers autoscale or if you rebuild your application completely.

Adding a new location block

The easiest extension is to add a new location block to the main server block. This can be done by placing a .conf file with a server block in the folder .platform/nginx/conf.d/elasticbeanstalk. Any such file is automatically included in the main server block.

Overriding the default location

@cb109
cb109 / remove_custom_fk_uniqueconstraint_django_mysql.md
Last active February 9, 2024 18:42
Fix: Cannot remove UniqueConstraint on ForeignKey with Django/MySQL

Django allows you to define custom UniqueConstraints to specify which combinations of values are allowed in a row, but removing these later can be problematic when some ForeignKey is involved, at least with MySQL it may throw a Cannot drop index '...': needed in a foreign key constraint at you.

The example below shows you how to resolve such a situation in 3 small individual migrations:

  • We start with an existing UniqueConstraint.
class MyModel(models.Model):
    other_model = models.ForeignKey("OtherModel", on_delete=models.CASCADE)
    name = models.CharField(max_length=128)
@andyraddatz
andyraddatz / ASCIIStringExtensions.cs
Last active May 29, 2024 15:10
C# String extension method to fold diacritics to ASCII characters
// IMPORTANT
using System.Text;
// This gist was created thanks to this comment from Alexander on StackOverflow:
// https://stackoverflow.com/questions/249087/how-do-i-remove-diacritics-accents-from-a-string-in-net#comment86833005_34272324
// This is a derivative work. The logic of this function comes from a switch statement found inside the
// Lucene.Net library. The documentation of the conversion of characters is quite impressive
// (thank you @NightOwl888 and @synhershko !!!):
// https://github.com/apache/lucenenet/blob/master/src/Lucene.Net.Analysis.Common/Analysis/Miscellaneous/ASCIIFoldingFilter.cs
@dennisslimmers
dennisslimmers / StripMarkdownTags.cs
Created December 13, 2017 10:43
C# Method for stripping Markdown tags from regular text
public class StringHelper
{
/// <summary>
/// https://github.com/stiang/remove-markdown/blob/master/index.js
/// </summary>
/// <param name="content"></param>
/// <returns></returns>
private string StripMarkdownTags(string content)
{
// Headers
@KKozlowski
KKozlowski / LaTeXPolishLeters.tex
Created November 3, 2016 10:23
Polish letters literation for LaTeX Listings package.
\usepackage{listings}
\lstset{
literate={ą}{{\k a}}1
{Ą}{{\k A}}1
{ż}{{\. z}}1
{Ż}{{\. Z}}1
{ź}{{\' z}}1
{Ź}{{\' Z}}1
{ć}{{\' c}}1
{Ć}{{\' C}}1
@jagrosh
jagrosh / Github Webhook Tutorial.md
Last active June 28, 2024 03:43
Simple Github -> Discord webhook

Step 1 - Make a Discord Webhook

  1. Find the Discord channel in which you would like to send commits and other updates

  2. In the settings for that channel, find the Webhooks option and create a new webhook. Note: Do NOT give this URL out to the public. Anyone or service can post messages to this channel, without even needing to be in the server. Keep it safe! WebhookDiscord

Step 2 - Set up the webhook on Github

  1. Navigate to your repository on Github, and open the Settings Settings
using System.ComponentModel;
using System.Globalization;
using System.Resources;
using System.Windows.Data;
public class TranslationSource
: INotifyPropertyChanged
{
private static readonly TranslationSource instance = new TranslationSource();
@myusuf3
myusuf3 / delete_git_submodule.md
Created November 3, 2014 17:36
How effectively delete a git submodule.

To remove a submodule you need to:

  • Delete the relevant section from the .gitmodules file.
  • Stage the .gitmodules changes git add .gitmodules
  • Delete the relevant section from .git/config.
  • Run git rm --cached path_to_submodule (no trailing slash).
  • Run rm -rf .git/modules/path_to_submodule (no trailing slash).
  • Commit git commit -m "Removed submodule "
  • Delete the now untracked submodule files rm -rf path_to_submodule
def nearby_spots_old(request, lat, lng, radius=5000, limit=50):
"""
WITHOUT use of any external library, using raw MySQL and Haversine Formula
http://en.wikipedia.org/wiki/Haversine_formula
"""
radius = float(radius) / 1000.0
query = """SELECT id, (6367*acos(cos(radians(%2f))
*cos(radians(latitude))*cos(radians(longitude)-radians(%2f))
+sin(radians(%2f))*sin(radians(latitude))))
@Ayrx
Ayrx / miller_rabin.py
Created June 28, 2013 13:47
Python implementation of the Miller-Rabin Primality Test
def miller_rabin(n, k):
# Implementation uses the Miller-Rabin Primality Test
# The optimal number of rounds for this test is 40
# See http://stackoverflow.com/questions/6325576/how-many-iterations-of-rabin-miller-should-i-use-for-cryptographic-safe-primes
# for justification
# If number is even, it's a composite number
if n == 2: