Skip to content

Instantly share code, notes, and snippets.

View jogaco's full-sized avatar
🎯
Focusing

J. Garcia jogaco

🎯
Focusing
View GitHub Profile
@jogaco
jogaco / BasicAuthAuthorizationInterceptor.java
Last active August 28, 2017 10:44
Java REST Web Service securization for Apache CXF 2.3.3 with Spring Security 3.0.5: Basic Authentication
import javax.ws.rs.core.Response;
import org.apache.cxf.configuration.security.AuthorizationPolicy;
import org.apache.cxf.interceptor.security.AccessDeniedException;
import org.apache.cxf.jaxrs.ext.RequestHandler;
import org.apache.cxf.jaxrs.model.ClassResourceInfo;
import org.apache.cxf.message.Message;
import org.apache.log4j.Logger;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.authentication.encoding.PasswordEncoder;
class ArticleImageUploader < ImageUploader
process :fix_exif_rotation
process :strip
process :convert => 'jpg'
process :quality => 85 # Percentage from 0 - 100
version :gallery_thumb do
process :resize_to_fill => Settings.images.article_images.processing.gallery_thumb #44x44
end
mysql -h $1 -e "create database $3 CHARACTER SET $character_set"
TRIGGERS=`mysql -h $1 $2 -e "show triggersG" | grep Trigger: | awk '{print $2}'`
VIEWS=`mysql -h $1 -e "select TABLE_NAME from information_schema.tables where table_schema='$2' and TABLE_TYPE='VIEW'" -sss`
if [ -n "$VIEWS" ]; then
mysqldump -h $1 $2 $VIEWS > /tmp/${2}_views${TIMESTAMP}.dump
fi
mysqldump -h $1 $2 -d -t -R -E > /tmp/${2}_triggers${TIMESTAMP}.dump
for TRIGGER in $TRIGGERS; do
echo "drop trigger $TRIGGER"
mysql -h $1 $2 -e "drop trigger $TRIGGER"
@jogaco
jogaco / apache-fakegooglebot
Created October 24, 2015 12:09
Alternative for fail2ban fake gooblebot detection when getting the error ImportError: No module named fail2ban.server.filter
#!/usr/bin/python
# Inspired by https://isc.sans.edu/forums/diary/When+Google+isnt+Google/15968/
#
# Written in Python to reuse built-in Python batteries and not depend on
# presence of host and cut commands
#
import sys
import socket
def process_args(argv):
@jogaco
jogaco / nginxlogs.sh
Created November 2, 2015 12:02
One liner for counting unique IP addresses from nginx rotating logs
ls -t /var/log/nginx/access.log.*.gz | xargs zcat | awk '{print $1}' | sort | uniq -c | sort -nr | head -n 100
@jogaco
jogaco / es_rolling_upgrade.sh
Created June 14, 2016 07:26
Script to install a rolling upgrade of ElasticSearch, for a single node setup. Checked in ubuntu
#!/bin/bash
display_usage() {
echo "This script must be run with super-user privileges."
echo -e "\nUsage:\n$0 [es-version e.g.: "2.3.3"] \n"
}
# check whether user had supplied -h or --help . If yes display usage
if [[ ( $# == "--help") || $# == "-h" ]]
then
class SitemapSettings
DEFAULT_HOST = 'http://www.example.com'
PUBLIC_PATH = 'private/'
SITEMAPS_PATH_NEW = 'sitemapsnew/'
SITEMAPS_PATH_PUBLISHED = 'sitemaps/'
DEFAULT_PRIORITY_MAP = [0.5]
end
@jogaco
jogaco / update-cloudflare-ips.sh
Created May 15, 2017 15:28
Cloudflare: automatic update of IP addresses
#!/bin/bash
# Location of the nginx config file that contains the CloudFlare IP addresses.
CF_NGINX_CONFIG="/etc/nginx/cloudflare-real-ip.conf"
CF_NGINX_CONFIG_NEW="/etc/nginx/cloudflare-real-ip.conf.new"
# The URLs with the actual IP addresses used by CloudFlare.
CF_URL_IP4="https://www.cloudflare.com/ips-v4"
CF_URL_IP6="https://www.cloudflare.com/ips-v6"
@jogaco
jogaco / pom.xml
Created May 21, 2017 15:40
Generated pom.xml for Spring Boot with JPA and MySql
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.operatornew</groupId>
<artifactId>spring-boot-mysql</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
@jogaco
jogaco / pom.xml
Last active May 21, 2017 16:25
Spring Boot tutorial: pom.xml fragment: schema properties
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<db.name>game_manager</db.name>
<jdbc.driverClassName>com.mysql.jdbc.Driver</jdbc.driverClassName>
<jdbc.url>jdbc:mysql://localhost/${db.name}?createDatabaseIfNotExist=true&amp;useUnicode=true&amp;characterEncoding=utf-8&amp;autoReconnect=true&amp;useJDBCCompliantTimezoneShift=true&amp;useLegacyDatetimeCode=false&amp;serverTimezone=UTC</jdbc.url>
<jdbc.username>username</jdbc.username>
<jdbc.password>password</jdbc.password>
</properties>