Skip to content

Instantly share code, notes, and snippets.

<?php
function get_tls_version($sslversion = null)
{
$c = curl_init();
curl_setopt($c, CURLOPT_URL, "https://www.howsmyssl.com/a/check");
curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
if ($sslversion !== null) {
curl_setopt($c, CURLOPT_SSLVERSION, $sslversion);
}
@amendezcabrera
amendezcabrera / ssh-telegram.sh
Created January 22, 2017 21:01 — forked from matriphe/ssh-telegram.sh
Bash Script to notify via Telegram Bot API when user log in SSH
# save it as /etc/profile.d/ssh-telegram.sh
# use jq to parse JSON from ipinfo.io
# get jq from here http://stedolan.github.io/jq/
USERID="<target_user_id>"
KEY="<bot_private_key>"
TIMEOUT="10"
URL="https://api.telegram.org/bot$KEY/sendMessage"
DATE_EXEC="$(date "+%d %b %Y %H:%M")"
TMPFILE='/tmp/ipinfo-$DATE_EXEC.txt'
if [ -n "$SSH_CLIENT" ]; then
@amendezcabrera
amendezcabrera / AnimateDrawerCloseButton.java
Created October 27, 2016 18:28 — forked from dolphinziyo/AnimateDrawerCloseButton.java
Moves a custom "close drawer button" and changes its alpha according to the Navigation Drawer opening offset
/**
* Moves a custom "close drawer button" and changes its alpha according to the Navigation Drawer opening offset
* @param offset Drawer opening offset
*/
private void animateDrawerCloseButton(float offset) {
imbtnCloseDrawerButton.setX(recyclerView.getX() + recyclerView.getWidth() + convertDpiToPixels(15)); // (15) Distance between the button and the Drawer
offset *= 255; // (255) Max alpha
imbtnCloseDrawerButton.getDrawable().setAlpha((int) offset);
}
@amendezcabrera
amendezcabrera / AnimateLayout.java
Created October 27, 2016 18:28 — forked from dolphinziyo/AnimateLayout.java
Animate a Layout using the Android Property Animation System
private void animateLayout(boolean mostrar) {
AnimatorSet set = (AnimatorSet) AnimatorInflater.loadAnimator(this, R.animator.slide_in_up);
set.addListener(new Animator.AnimatorListener() {
@Override
public void onAnimationStart(Animator animation) {
}
@Override
public void onAnimationEnd(Animator animation) {
layout.setVisibility(View.GONE);
@amendezcabrera
amendezcabrera / SetImageButtonTintOnTouch.java
Created October 27, 2016 18:27 — forked from dolphinziyo/SetImageButtonTintOnTouch.java
Changes the tint of all the ImageButton sent via parameter
private Rect rect;
public void setImageButtonTintOnTouch(ImageButton... listaImbtn) {
for (ImageButton imbtn : listaImbtn) {
imbtn.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
rect = new Rect(v.getLeft(), v.getTop(), v.getRight(), v.getBottom());
((ImageButton) v).setColorFilter(Color.argb(100, 0, 0, 0)); // Can cause ClassCastException
} else if (event.getAction() == MotionEvent.ACTION_UP) {
@amendezcabrera
amendezcabrera / GetRandomPhrase.java
Created October 27, 2016 18:26 — forked from dolphinziyo/GetRandomPhrase.java
Return a random phrase from the strings.xml file starting by the required string ID
public void initializePhrases() {
Field[] fields = R.string.class.getFields();
loadingPhrasesList = new ArrayList<>();
String requiredIdStart = "loading_window_message_"; // Required string ID. In strings.xml file, the ID of the string must be "loading_window_message_" plus a number from 0 to inifinite (not so long :)
for (int i = 0; i < fields.length; i++) {
try {
String stringIdStart = fields[i].getName().substring(0, idStartText.length());
if (stringIdStart.equals(requiredIdStart)) {
loadingPhrasesList.add(fields[i].getName());
}