Skip to content

Instantly share code, notes, and snippets.

View amr's full-sized avatar

Amr Youssef amr

  • Affirm
  • San Francisco, CA
View GitHub Profile
@amr
amr / ConfigurationLoader.java
Last active November 11, 2023 18:43
Java simple YAML/JSON/Properties configuration mechanism with environment variable substitution/interpolation
public class ConfigurationLoader {
private final ObjectMapper objectMapper;
private final StringSubstitutor stringSubstitutor;
ConfigurationLoader() {
this.objectMapper = new ObjectMapper(new YAMLFactory());
this.stringSubstitutor =
new StringSubstitutor(StringLookupFactory.INSTANCE.environmentVariableStringLookup());
}
@amr
amr / find-futex-wait.sh
Created November 30, 2010 18:37
Find processes executing futex with FUTEX_WAIT (helps find deadlock-ed processes)
#!/bin/bash
#
# Find all processes that are executing a futex(2) call with op=FUTEX_WAIT
# In some cases this can be helpful in finding deadlock-ed processes.
#
test ! $UID -eq 0 && echo -e "WARNING: Not running as root, only processes for this user are being scanned\n" >&2;
pids=$(ps -u $UID -opid --no-headers)
for pid in $pids; do
@amr
amr / my.ini
Last active September 30, 2020 17:46
MySQL my.cnf settings optimized for local development, this is NOT a complete my.cnf configuration, the settings here are meant to be copied from their sections and pasted in the appropriate section in an existing working my.cnf
[mysqld]
open-files-limit = 24000
character-set-server = utf8
character-set-filesystem = utf8
#
# InnoDB
#
# After applying these for the first time on a new mysql installation with no
@amr
amr / avg-apache-process.sh
Created May 11, 2011 10:11
Tells you the average size of your Apache processes
#!/bin/bash
#
# Tells you the average size of your Apache processes
# It must run on a live apache server (unless you know what you are doing).
# It requires pmap, /proc, ps, grep, awk, sed and bc,
#
# Written by: Amr Mostafa" <amr.mostafa@egyptdc.com>
#
# Courtesy of Egypt Development Centre (c).
@amr
amr / tmpdir.scala
Created October 2, 2014 10:04
Create temporary directory with the JVM (Scala here)
def createTempDir(tmpName: String): String = {
val tmpDir = Paths.get(System.getProperty("java.io.tmpdir"))
val name: Path = tmpDir.getFileSystem.getPath(tmpName)
if (name.getParent != null) throw new IllegalArgumentException("Invalid prefix or suffix")
tmpDir.resolve(name).toString
}
@amr
amr / ConstraintViolationPathUtils.java
Created March 3, 2017 10:05
Mapping ConstraintViolatation paths to JSON Pointer and JSON Path
import com.fasterxml.jackson.core.JsonPointer;
import javax.validation.ElementKind;
import javax.validation.Path;
import javax.validation.Path.Node;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;
/**
* This has not been extensively tested. It's just a starting point. Please improve!
@amr
amr / GooglePlayServicesInterstitial.java
Last active January 3, 2016 03:28
MoPub adapter to serve AdMob's interstitials with the new Google Play Services API.
/*
* This a modified version based on code by MoPub Inc.
* The author's modifications are released into the public domain. MoPub .inc code
* is originally released under the license below.
*
* Copyright (c) 2010-2013, MoPub Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
@amr
amr / convert-security-defs.py
Created September 3, 2012 11:39
SS2 Security Permissions Defs to SS3 intercept-url tag
#!/usr/bin/env python
def is_comment(line):
return line.startswith('<!--')
def is_empty(line):
return len(line) == 0
if __name__ == '__main__':
f = open('/tmp/definitions.txt', 'r')
<?php
/**
* @file
* Retrieves various load indicators from servers using SNMP.
*
* Licensed under GPL v3 or later.
* Copyright 2009 (c) Egypt Development Center.
*/
/**
#!/bin/bash
SLEEP=1
THRESHOLD=500
while [ 1 ]
do
threads=`mysqladmin stat | awk '{ print $4 }'`
echo "Active threads: $threads"
if [ $threads -gt $THRESHOLD ]; then
log="/root/mysql-monitor/logs/sqls-$threads-`date +%s`.log"