Skip to content

Instantly share code, notes, and snippets.

View olivx's full-sized avatar

Thiago Oliveira olivx

  • Tivit
  • Sao Paulo
View GitHub Profile
mkdir ~/.npm-global
npm config set prefix '~/.npm-global'
export PATH=~/.npm-global/bin:$PATH
source ~/.profile
NPM_CONFIG_PREFIX=~/.npm-global
echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p
fs.inotify.max_user_watches=524288
sysctl --system
# Hack to cache SELECT statements inside a single Django request. The patch() method replaces
# the Django internal execute_sql method with a stand-in called execute_sql_cache. That method
# looks at the sql to be run, and if it's a select statement, it checks a thread-local cache first.
# Only if it's not found in the cache does it proceed to execute the SQL. On any other type of
# sql statement, it blows away the cache. There is some logic to not cache large result sets,
# meaning anything over 100 records. This is to preserve Django's lazy query set evaluation.
from threading import local
@olivx
olivx / context.py
Last active October 10, 2018 13:27
my_applicants = Model.object.all()
context['next'] = next_in_order(obj, qs=my_applicants)
context['prev'] = prev_in_order(obj, qs=my_applicants, loop=True)
@olivx
olivx / filter_applicants.py
Last active September 22, 2018 00:11
filter_applicants multiples elements separator per ', ' example with Q() object
def add_q_object(self, keyword, q_object, query_parm):
for key in keyword:
kwargs = {query_parm: key.strip()}
q_object.add(Q(**kwargs), q_object.OR)
def filter_applicants(self, _queryset=None):
my_applicants = _queryset
<div class="card">
<div class="card-header">
<span style="display:block">
<span data-target="#job-{{ job.ref_number }}" data-toggle="collapse"
class="text-muted pull-right el-collpse" style="cursor: pointer" aria-expanded="false">
<i class="fa fa-angle-right js-rotate-if-collapsed"></i>
</span>
</span>
<span style="display:block">
{{ job.title }}
import time
from datetime import datetime , timedelta
from dateutil.rrule import rrule, MONTHLY, DAILY
date_start_obj = datetime(2018,05,18)
date_end_obj = datetime(2018,05,30)
# holidays = [datetime(2018,05,21).date(), datetime(2018,05,28).date(), datetime(2018,05,20).date()]
def get_working_days(date_start_obj, date_end_obj, holidays=[]):
many_holidays = 0
@import "https://fonts.googleapis.com/css?family=Dosis:300,400,500,600,700";
#timeline .timeline-item:after, #timeline .timeline-item:before {
content: '';
display: block;
width: 100%;
clear: both;
}
*, *:before, *:after {
box-sizing: border-box;
-webkit-box-sizing: border-box;
// Bootstrap datepicker
$('.input-daterange input').each(function() {
$(this).datepicker('clearDates');
});
// Set up your table
table = $('#my-table').DataTable({
paging: false,
info: false
});
@olivx
olivx / decorator_protect_views.py
Created August 4, 2018 00:06
protect acess url views
from django.contrib.auth import REDIRECT_FIELD_NAME
from django.contrib.auth.decorators import user_passes_test
from account.models import Profile
def client_user_denied(function=None, redirect_field_name=REDIRECT_FIELD_NAME, login_url='account:login'):
actual_decorator = user_passes_test(
lambda u: u.is_active and u.profile.type > 0,
login_url=login_url, redirect_field_name=redirect_field_name
)
@olivx
olivx / responsivel_table.css
Created July 28, 2018 14:47
responsivel table
/*
Max width before this PARTICULAR table gets nasty. This query will take effect for any screen smaller than 760px and also iPads specifically.
*/
@media
only screen
and (max-width: 760px), (min-device-width: 768px)
and (max-device-width: 1024px) {
/* Force table to not be like tables anymore */
table, thead, tbody, th, td, tr {