Skip to content

Instantly share code, notes, and snippets.

View paulocheque's full-sized avatar

Paulo Cheque paulocheque

View GitHub Profile
@paulocheque
paulocheque / .bash_profile
Last active September 30, 2023 17:26
.bash_profile example
# EDITOR=nano sudo visudo
# Change the following line: (:i to insert + esc to go back + :w to save + :q to quit)
# Defaults env_reset
# to:
# Defaults env_reset,timestamp_timeout=960 # in minutes
export PATH=$PATH:.
# export PATH=$PATH:/usr/bin
@paulocheque
paulocheque / tools.md
Last active October 20, 2022 14:33
Essential Dev Tools

Basic

  • Sublime 3
    • Package Control
    • Markdown highlight
    • INI highlight
    • Nginx highlight
    • Play highlight
    • Python improved
  • Generic Config highlight
@paulocheque
paulocheque / flatten.py
Last active May 13, 2019 13:08
Flatten list in Python 3
'''
MIT license: http://opensource.org/licenses/MIT
Copyright (c) <2013> <Paulo Cheque>
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
@paulocheque
paulocheque / find_seq.py
Created July 8, 2017 18:30
Find a seq in a list
def find_seq(seq, alist):
'''
Find the sequence @seq in the list @alist.
@seq: a list or tuple with size `m`.
@alist: a list or tuple with size `n`.
@return: True if @alist contains @seq, False otherwise.
Complexity: `O((n-m) * m) = O(n * m)`
'''
@paulocheque
paulocheque / mysql.md
Last active February 27, 2016 16:52
SQL

Commands

sudo mysqld_safe

Select a random row

SELECT column FROM table
ORDER BY RAND()

LIMIT 1

@paulocheque
paulocheque / convert_image.py
Last active January 11, 2016 19:20
image processing
import os
from os import listdir
from os.path import isfile, join
from invoke import run, task
dirpath = './mypath'
@task
def resize():
#http://www.imagemagick.org/Usage/resize/#resize
@paulocheque
paulocheque / file_manager.py
Last active December 21, 2015 02:09
Python dealing with files
# -*- coding: utf-8 -*-
import os
import tempfile
from shutil import rmtree, copy2
TEMP_PATH = tempfile.gettempdir() or os.environ.get('TEMP')
@paulocheque
paulocheque / _localhost.json
Last active December 19, 2015 05:49
Fabric script
{
"python": "pypy",
"url": "http://localhost:8000",
"host": "localhost",
"port": 8000,
"heroku_app": null,
"heroku_app_addons": [],
"heroku_worker": null,
"heroku_worker_addons": [],
"heroku_cedar": null,
@paulocheque
paulocheque / benchmarks.sh
Last active December 15, 2015 14:18
Benchmarks
# ab -n 2000 -c 200 https://url/
install_dependencies() {
brew install freetype
brew install libpng
brew install libevent
virtualenv venv --no-site-packages
source venv/bin/activate
pip install numpy
pip install matplotlib
@paulocheque
paulocheque / BaseRakefile.rake
Last active December 14, 2015 16:09
Rake scripts
# You may put this on the rakelib directory or renamed it to .rb and add a 'require' command
MAIN_PATH = File.dirname(__FILE__)
module OS
def OS.windows?
(/cygwin|mswin|mingw|bccwin|wince|emx/ =~ RUBY_PLATFORM) != nil
end
def OS.mac?