Skip to content

Instantly share code, notes, and snippets.

@mrk21
mrk21 / config-initializers-trusted_proxies.rb
Created August 31, 2019 10:07
How to get a remote ip on CloudFront + Rails
# @see https://docs.aws.amazon.com/ja_jp/AmazonCloudFront/latest/DeveloperGuide/LocationsOfEdgeServers.html
# @see https://morizyun.github.io/ruby/rails-controller-get-ip.html
# @see https://dev.classmethod.jp/cloud/aws/get-ec2-public-ip-range-by-powershell/
# @see https://github.com/rails/rails/blob/c81af6a/actionpack/lib/action_dispatch/middleware/remote_ip.rb#L112-L150
Rails.application.configure do
ip_ranges_res = Faraday.get('https://ip-ranges.amazonaws.com/ip-ranges.json')
ip_ranges = JSON.parse(ip_ranges_res.body)
cloudfront_ips = ip_ranges['prefixes'].select { |v| v['service'] == 'CLOUDFRONT' }.map { |v| IPAddr.new(v['ip_prefix']) } +
ip_ranges['ipv6_prefixes'].select { |v| v['service'] == 'CLOUDFRONT' }.map { |v| IPAddr.new(v['ipv6_prefix']) }
<!-- add this to your header -->
<div id="google_translate_element"></div>
<!-- to your js part -->
<script src="script.js"></script>
<script type="text/javascript">
function googleTranslateElementInit() {
new google.translate.TranslateElement(
{pageLanguage: 'en'},
'google_translate_element'
@wkrea
wkrea / textlive-full-beefless.md
Created September 2, 2020 13:30 — forked from shivams/textlive-full-beefless.md
`texlive-full` without the beef

TLDR;

On an Debian/Ubuntu-based system, to install texlive-full without docs and language packs, simply do this:

sudo apt install `sudo apt --assume-no install texlive-full | \
		awk '/The following additional packages will be installed/{f=1;next} /Suggested packages/{f=0} f' | \
		tr ' ' '\n' | grep -vP 'doc$' | grep -vP 'texlive-lang' | grep -vP 'latex-cjk' | tr '\n' ' '`

After this, if you wish to install the language packs, selectively install them. E.g.:

@mjallday
mjallday / currencies.py
Created August 12, 2011 09:09
Tuple of currencies for Python
# -*- coding: utf-8 -*-
"""
list of currencies currently in circulation
taken from http://www.currency-iso.org/iso_index/iso_tables/iso_tables_a1.htm
http://www.iso.org/iso/currency_codes_list-1.html
2011-08-11
"""
@heitorlessa
heitorlessa / example_minio_boto3.py
Created August 30, 2016 14:18
Minio with python boto3
# Sample as to how to initialize s3 client to work with Minio API compatible - https://github.com/minio/minio
# AWS CLI counterpart - https://docs.minio.io/docs/aws-cli-with-minio
import boto3
s3 = boto3.resource('s3',
endpoint_url='http://<minio_IP>:9000',
config=boto3.session.Config(signature_version='s3v4')
)
@appkr
appkr / AddressRefiner.java
Last active May 21, 2024 14:32
주소정제기 초벌
package com.vroong.neogeo.support.address.refiner;
import static com.vroong.neogeo.domain.AdditionalInfo.*;
import static com.vroong.neogeo.domain.RegionType.*;
import static com.vroong.neogeo.support.address.Regex.*;
import com.vroong.neogeo.domain.AddressEntry;
import com.vroong.neogeo.domain.AddressEntry.AddressEntryBuilder;
import com.vroong.neogeo.domain.Refinable;
import com.vroong.neogeo.support.address.Regex;
Asynchronous Request/Response in Our Application
This document provides a step-by-step guide on how to implement asynchronous request/response in our application. The process involves changes in both the backend and frontend.
Backend
Step 1: Include AsyncRequestHandler
Include the AsyncRequestHandler concern in the intended controller where you want to enable asynchronous requests.
class EndUser::PearsonUserAssessmentsController < ApplicationController
include AsyncRequestHandler
end
@wojteklu
wojteklu / clean_code.md
Last active May 21, 2024 14:31
Summary of 'Clean code' by Robert C. Martin

Code is clean if it can be understood easily – by everyone on the team. Clean code can be read and enhanced by a developer other than its original author. With understandability comes readability, changeability, extensibility and maintainability.


General rules

  1. Follow standard conventions.
  2. Keep it simple stupid. Simpler is always better. Reduce complexity as much as possible.
  3. Boy scout rule. Leave the campground cleaner than you found it.
  4. Always find root cause. Always look for the root cause of a problem.

Design rules

Edge Chromium

Note: If your system region is part of the EEA the option to uninstall Edge normally is rolling out in the latest updates for Windows and Edge. With some registry edits, you can change the region after install.

HKLM\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\Microsoft Edge, remove NoRemove.

HKLM\SOFTWARE\WOW6432Node\Microsoft\EdgeUpdate\ClientState\{56EB18F8-B008-4CBD-B6D2-8C97FE7E9062}, delete experiment_control_labels if it exists.

Create HKLM\SOFTWARE\WOW6432Node\Microsoft\EdgeUpdateDev and add the AllowUninstall value. This replaces the experiment_control_labels blocker on later versions of Edge.

@senjacob
senjacob / ColumnAttributeTypeMapper.cs
Last active May 21, 2024 14:28 — forked from kalebpederson/ColumnAttributeTypeMapper.cs
Map column names with class properties in Dapper-dot-net using ITypeMap and CustomAttributes
namespace YourNamespace
{
/// <summary>
/// Uses the Name value of the ColumnAttribute specified, otherwise maps as usual.
/// </summary>
/// <typeparam name="T">The type of the object that this mapper applies to.</typeparam>
public class ColumnAttributeTypeMapper<T> : FallbackTypeMapper
{
public static readonly string ColumnAttributeName = "ColumnAttribute";