Skip to content

Instantly share code, notes, and snippets.

View paulocheque's full-sized avatar

Paulo Cheque paulocheque

View GitHub Profile
@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 / 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 / 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
import timeit
import random
def bench(stmt, setup, n=1000, repeat=10):
'''
Run `repeat` times the `timeit` with:
Run `n` times the `stmt`
'''
r = timeit.repeat(stmt, setup=setup, number=n, repeat=repeat)
@paulocheque
paulocheque / network.sh
Last active August 29, 2015 14:06
network commands
Network
================================
ping ip/dns
telnet ip/dns:port
netstat
http
iptables
sudo lsof -i :5955 # check which process is using port 5955
@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 / 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 / benchmark.py
Last active August 29, 2015 14:05
benchmarks
import json
import re
import timeit
import ujson
import simplejson
# from memory_profiler import profile
# @profile(precision=4)
@paulocheque
paulocheque / ssh
Last active August 29, 2015 14:04
Amazon
mv file.pem ~/.ssh/
chmod 400 ~/.ssh/file.pem
ssh -v -i ~/.ssh/file.pem ubuntu@ip
scp -i ~/.ssh/file.pem file ubuntu@ip:~
scp -i ~/.ssh/file.pem ubuntu@ip:~/file .
http --follow POST url attr=value attr2=value2 --print=h
http GET url --print=h