Skip to content

Instantly share code, notes, and snippets.

@e23z
e23z / configure.cs
Created July 25, 2017 18:39
[CORs .NET Core] How to enable cors on a .net core app. #csharp #netcore #mvc #security #cors
public void ConfigureServices(IServiceCollection services)
{
// Add service and create Policy with options
services.AddCors(options =>
{
options.AddPolicy("CorsPolicy",
builder => builder.AllowAnyOrigin()
.AllowAnyMethod()
.AllowAnyHeader()
.AllowCredentials() );
@e23z
e23z / metas.html
Created July 25, 2017 18:47
[Chrome Headerbar Color] How to change the color of chrome browser headerbar on ios or android. #html #ui
<!-- Chrome, Firefox OS and Opera -->
<meta name="theme-color" content="#4285f4">
<!-- Windows Phone -->
<meta name="msapplication-navbutton-color" content="#4285f4">
<!-- iOS Safari -->
<meta name="apple-mobile-web-app-status-bar-style" content="#4285f4">
@e23z
e23z / prevent_zoom.html
Created July 25, 2017 18:53
[Prevent Zoom on Mobile] How to prevent form zooming on a mobile page on mobile devices. #html #forms #ios #ui #ux
<!-- it seems it doesn't work anymore since ios 10 release -->
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0"/>
<!-- or simply -->
<!-- set font-size:16px to all input fields. -->
@e23z
e23z / latin.txt
Created July 25, 2017 20:41
[Latin Chars Regex] Detecting latin ("accented") chars in a string with regex. #regex
[a-zA-ZÀ-ÿ0-9 ][a-zA-ZÀ-ÿ0-9 ][a-zA-ZÀ-ÿ0-9 ]+
[\w\u0000-\u024F\-]+
@e23z
e23z / regex.txt
Created July 25, 2017 20:42
[String between Chars] How to get a value between two chars with regex. In this case, parenthesis ("(...)"). #regex
\(([^)]+)\)
@e23z
e23z / regex.md
Last active July 25, 2017 20:44
[E-mail Validation Regex] Regex for e-mail validation. #regex

RFC 5322 Official Standard

(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])

python

r"(^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$)"
@e23z
e23z / elasticsearch.py
Created July 25, 2017 20:50
[ElasticSearch Examples] A simple script demonstrating how to create indexes, delete them, inserting items, querying them and so on. #python #elasticsearch #demo
from elasticsearch import Elasticsearch
from elasticsearch.client import IndicesClient
import sys
es = Elasticsearch([{'host': 'localhost', 'port': 9200}])
idx = IndicesClient(es)
# deleting an index
idx.delete(index = 'hivebot')
@e23z
e23z / Vagrantfile_multimachine.rb
Created July 25, 2017 21:04
[Vagrantfile] Template of simple vagrantfile for parallels desktop. #vagrant #template
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure(2) do |config|
config.vm.box = "parallels/ubuntu-16.04"
config.vm.provision "shell", inline: <<-SHELL
SHELL
#
# MACHINES
@e23z
e23z / iis6.xml
Created July 25, 2017 21:05
[IIS Max Upload] How to increase the max_upload_file_size limit of IIS.
<configuration>
<system.web>
<httpRuntime maxRequestLength="xxx" />
</system.web>
</configuration>
@e23z
e23z / geolocation.sql
Created July 25, 2017 21:11
[Closest Geolocation] How to query the closest geolocation to a longitude/latitude in MySQL. #mysql #queries #geolocation
SELECT S.`id`, S.`name`, A.latitude, A.longitude,
(
3959 *
ACOS(
COS(RADIANS(@orig_lat)) *
COS(RADIANS(A.latitude)) *
COS(RADIANS(A.longitude) - RADIANS(@orig_lon)) +
SIN(RADIANS(@orig_lat)) *
SIN(RADIANS(A.latitude))
)