Skip to content

Instantly share code, notes, and snippets.

View caruccio's full-sized avatar
😐
state = not in mood

Mateus Caruccio caruccio

😐
state = not in mood
View GitHub Profile
#!/usr/bin/env python
# Returns true (0) if $1 is on $PATH, false (1) otherwise
# Handles path expansions as expected
# Example: is_dir_on_path ~/bin
is_dir_on_path()
{
local path
local dir
# convert $PATH to array
@caruccio
caruccio / shopt-toggler.sh
Created March 22, 2016 14:13
How to toggle a shopt flag
# Lets assume you need to turn on a shopt (dotglob, for example),
# do some work and finally turn it back to it's original state.
# First we check if it's on already (shopt -q <flag>),
# and set a flag variable in case it was.
# Otherwise we turn it on and ensure the flag is clear (unset <flag>).
shopt -q dotglob && dotglob=1 || { shopt -s dotglob && unset dotglob; }
## Here we can do whatever we need to do...
<script type='text/javascript' src='https://code.jquery.com/jquery-3.1.0.min.js'></script>
<script type='text/javascript'>
$(document).ready(function ()
{
$('#show-password').change(function() {
$('#password').prop('type', this.checked ? 'text' : 'password')
})
$('#signup-form').submit(function(event) {
#!/bin/bash
# Salve este arquivo em seu repositorio, no caminho ".s2i/bin/assemble"
if [ "$STI_SCRIPTS_PATH/assemble" ]; then
source $STI_SCRIPTS_PATH/assemble
fi
# Faça o que voce precisa aqui...
@caruccio
caruccio / infinite-stream-post.py
Created August 12, 2016 12:31
Post infinite data to URL
from contextlib import contextmanager
import requests
import io
import sys
import time
class Streamer(io.TextIOBase):
def readline(self, limit=-1):
time.sleep(0.5)
return '.' * (1024 if limit <= 0 else limit) + "\n"
@caruccio
caruccio / defparamval.py
Created August 26, 2016 13:06
Default parameter value instead globals
# Instead of defining a global to use inside your function, just define it as a default
# value of the function, specially if the value can cost some significant time
regex = re.compile('[^0-9]') # globals are evil (are they?)
def clean_zip(string):
return regex.sub('', string)
# This way we execute re.compile a single time AND have the advantage to overwrite it when necessary
def clean_zip(string, regex=re.compile('[^0-9]')):
@caruccio
caruccio / Dockerfile
Created December 21, 2016 13:34
Dockerfile for GetupCloud's php-7.0 (original: https://github.com/getupcloud/sti-php/blob/master/7.0/Dockerfile)
FROM openshift/base-centos7
# This image provides an Apache+PHP environment for running PHP
# applications.
MAINTAINER Mateus Caruccio <mateus.caruccio@getupcloud.com>
EXPOSE 8080
ENV PHP_VERSION=7.0
@caruccio
caruccio / mariadb-galera-persistent-template.yml
Last active May 24, 2017 14:58
MariaDB Galera Cluster Openshift Template
# Source: https://github.com/getupcloud/openshift-mariadb-galera/blob/master/mariadb-galera-persistent-template.yml
---
kind: Template
apiVersion: v1
metadata:
name: mariadb-galera-persistent
annotations:
description: MariaDB Galera cluster persistent (NFS)
iconClass: icon-mariadb
tags: database,mysql,replication,mariadb,galera,nfs
@caruccio
caruccio / underlinize.md
Created July 26, 2017 15:34
Converting text to single char

Check ou this trick to convert any text into a sequence of chars of the same length

$ MESSAGE="Some arbitrary message to convert into dashes"
$ echo "$MESSAGE" | tr "$MESSAGE" -

I like to use it to "underlinize" titles on my scripts