Skip to content

Instantly share code, notes, and snippets.

View vladzloteanu's full-sized avatar

Vlad Zloteanu vladzloteanu

View GitHub Profile
# DockerFile
FROM php:5.6-cli
# Install Composer
COPY --from=composer /usr/bin/composer /usr/bin/composer
#RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
RUN apt-get -qq update && apt-get -qq install mysql-client python3 libxml++2.6-dev > /dev/null
- name: Get hostname
shell: echo $HOSTNAME
register: local_hostname
delegate_to: localhost
- name: Get current user
shell: whoami
register: local_user
delegate_to: localhost
function getReadableFileSizeString(fileSizeInBytes) {
var i = -1;
var byteUnits = [' kB', ' MB', ' GB', ' TB', 'PB', 'EB', 'ZB', 'YB'];
do {
fileSizeInBytes = fileSizeInBytes / 1024;
i++;
} while (fileSizeInBytes > 1024);
return Math.max(fileSizeInBytes, 0.1).toFixed(1) + byteUnits[i];
};
{% macro form_field(field) -%}
{% set with_label = kwargs.pop('with_label', False) %}
{% set placeholder = '' %}
{% if not with_label %}
{% set placeholder = field.label.text %}
{% endif %}
<div class="control-group {% if field.errors %}error{% endif %}">
{% if with_label %}
<label for="{{ field.id }}" class="control-label">
{{ field.label.text }}{% if field.flags.required %} *{% endif %}:
@vladzloteanu
vladzloteanu / gist:8695023
Created January 29, 2014 19:24
Flask test client using full URL
import unittest
from flask import Flask, request
app = Flask(__name__)
app.testing = True
@app.route('/action')
def action():
return ""
@vladzloteanu
vladzloteanu / gist:3793566
Created September 27, 2012 11:39
Mongoid persistence mode (fire and forget by default)
class MyModel
include Mongoid::Document
include Mongoid::Timestamps
field :value, :type => String
index :value, :unique => true
attr_accessible :value
end
/* Wed 14-32-41_user-jeremy-dai-334314.custom_stylesheet.e7d5.txt */
#bd .last_feedbacks_widget div.feedback div.metadata dl.vote dd.controls li.score-control-plus {left:3px;}
#bd .last_feedbacks_widget div.feedback,
#bd .most_consulted_feedbacks_widget div.feedback {margin-bottom:30px;height:200px;}
#bd .small ul.feedbacks li.feedback, #bd div.sliding_panel ul.feedbacks li.feedback {margin-bottom:0;}
.link-to-feedback {display:none;}
@vladzloteanu
vladzloteanu / gist:2020974
Created March 12, 2012 09:54
Performance profiling
# Log all slow Rails queries
grep -E -i "Load|Update|SQL|COUNT" answers.log | grep -E '\([2-9][0-9]{3,}\.[0-9]*ms\)' | sed 's/.*(\([0-9]*\)\.[0-9]*ms)/\1/g' > /home/vlad/profiling/slow_answers_queries.sql
grep -E -i "Load|Update|SQL|COUNT" auth.log | grep -E '\([1-9][0-9]{3,}\.[0-9]*ms\)' | sed 's/.*(\([0-9]*\)\.[0-9]*ms)/\1/g' > /home/vlad/profiling/slow_auth_queries.sql
## Ideas app
# test normal download
curl "https://domain-test.ideas.dimelo.com" --silent --silent --write-out "size_download=%{size_download}\n" --output /dev/null
@vladzloteanu
vladzloteanu / gist:2017546
Created March 11, 2012 18:24
MySQL goodies
# Total size of data + indexes for *ALL* DBs
SELECT table_schema "DB Name", ROUND(SUM(data_length) / 1024 / 1024, 2) "Data size (MB)", ROUND(SUM(data_length + index_length) / 1024 / 1024, 2)
"Data + Indexes size (MB)" FROM information_schema.TABLES GROUP BY table_schema ;
# Total size of data + indexes for *ALL* Tables in a DB
SELECT TABLE_NAME, table_rows, data_length, index_length, round(((data_length + index_length) / 1024 / 1024),2) "Total size (MB)"
FROM information_schema.TABLES WHERE table_schema = "db_name";
@vladzloteanu
vladzloteanu / gist:2000372
Created March 8, 2012 10:48
OSX Lion: SSL verification issue: Reinstall Ruby with OpenSSL support (with rvm)
# Bug report: http://www.ruby-forum.com/topic/208026
#
## Reproduce bug
require 'socket'
require 'openssl' # Should return true
s = TCPSocket.new 'bugzilla.redhat.com', 443
ctx = OpenSSL::SSL::SSLContext.new