Skip to content

Instantly share code, notes, and snippets.

@milhomem
milhomem / clientCertSign.php
Last active March 25, 2017 17:38
Generating Client Certificate on-demand with PHP and phpseclib
$privateKeyIntermediateCA = new \Crypt_RSA();
$privateKeyIntermediateCA->setPassword('Intermediate CA password');
$privateKeyIntermediateCA->loadKey(file_get_contents($privateCAKeyPath));
$certificateIntermediateCA = new \File_X509();
$certificateIntermediateCA->setPrivateKey($privateKeyIntermediateCA);
$certificateIntermediateCA->loadX509(file_get_contents($certificateCAKeyPath));
$clientPrivateKey = new \Crypt_RSA();
$clientPrivateKey->setPassword($password);
@milhomem
milhomem / clientCert.android.java
Last active April 18, 2024 21:18
How to connect using Client Certificate in Android with OkHttp
KeyStore keyStore = KeyStore.getInstance("PKCS12");
FileInputStream clientCertificateContent = new FileInputStream("/path/to/publicAndPrivateKey.p12");
keyStore.load(clientCertificateContent, "private key password".toCharArray());
KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
keyManagerFactory.init(keyStore, "private key password".toCharArray());
FileInputStream myTrustedCAFileContent = new FileInputStream("/path/to/embedded/CA-Chain.pem");
CertificateFactory certificateFactory = CertificateFactory.getInstance("X.509");
X509Certificate myCAPublicKey = (X509Certificate) certificateFactory.generateCertificate(myTrustedCAFileContent);
@milhomem
milhomem / backup-all-git-repos.sh
Created March 12, 2016 14:30
Backup git repository to another remote
#!/bin/bash
#
# Given a GIT repository with two remotes, uses one as `origin`
# and other as `destination` for the backup.
# Usage:
# /usr/bin/backup-all-git-repos.sh [repo-name]
# repo-name: Name of the repository to backup, is actually
# the directory of the repository in the FS.
# If specified only backups that repository.
#
@milhomem
milhomem / php-code-coverage.sh
Last active March 26, 2018 09:37
Script to show us difference of coverage when adding or changing code with PHPUnit
#!/bin/bash
#Reference: http://archive.gregk.me/2011/phpunit-command-line-code-coverage-summary/
COVERAGE=""
METRICS="/tmp/phpunit-metrics.xml"
BEFORE="/tmp/before-wip"
AFTER="/tmp/after-wip"
if [ "$1" == "--clean" ]
then
rm -f $METRICS $BEFORE $AFTER
@milhomem
milhomem / gerrit_google_oauth
Created May 6, 2015 01:13
Associate google account OAuth with existing gerrit account
-- SELECT OLD AND NEW INFORMATION IF EMAIL ARE THE SAME
select * from account_external_ids where EMAIL_ADDRESS = 'XXXXX@XXXX';
-- NEW ID
delete from account_external_ids where account_id= NEW_ID;
delete from accounts where ACCOUNT_ID= NEW_ID;
-- OLD ID
INSERT INTO account_external_ids values (OLD_ID, 'XXXXX@XXXX'', NULL, OAUTH_IDENTIFIER);
@milhomem
milhomem / diff_jsons
Created May 2, 2015 06:32
Diff two Json files
cat /tmp/json_a | php -r '$f=file("php://stdin"); $a = json_decode(join($f), true); function ksortRecursive(&$array, $sort_flags = SORT_REGULAR) { if (!is_array($array)) return false; ksort($array, $sort_flags); foreach ($array as &$arr) { ksortRecursive($arr, $sort_flags); } return true; }; ksortRecursive($a); echo var_export($a,true);' > /tmp/json_a_sorted
cat /tmp/json_b | php -r '$f=file("php://stdin"); $a = json_decode(join($f), true); function ksortRecursive(&$array, $sort_flags = SORT_REGULAR) { if (!is_array($array)) return false; ksort($array, $sort_flags); foreach ($array as &$arr) { ksortRecursive($arr, $sort_flags); } return true; }; ksortRecursive($a); echo var_export($a,true);' > /tmp/json_b_sorted
diff /tmp/json_a_sorted /tmp/json_b_sorted -u --ignore-all-space
@milhomem
milhomem / migration53.xml.diff
Created December 14, 2014 21:52
Translate PHP docs
Index: pt_BR/appendices/migration53.xml
===================================================================
--- pt_BR/appendices/migration53.xml (revision 335291)
+++ pt_BR/appendices/migration53.xml (working copy)
@@ -1,41 +1,43 @@
<?xml version="1.0" encoding="utf-8"?>
-<!-- $Revision$ -->
+<!-- EN-Revision: 331031 Maintainer: rogerioprado Status: wip --><!-- CREDITS: milhomem -->
<appendix xml:id="migration53" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
- <title>Migrating from PHP 5.2.x to PHP 5.3.x</title>