Skip to content

Instantly share code, notes, and snippets.

View osharim's full-sized avatar
🎯
Focusing

Omar Hernandez osharim

🎯
Focusing
  • México
View GitHub Profile
@olooney
olooney / cropped_thumbnail.my
Created January 12, 2012 16:31
A "better" thumbnail algorithm for Python Image Library PIL Image
'''
PIL's Image.thumbnail() returns an image that fits inside of a given size (preserving aspect ratios)
but the size of the actual image will vary and is certainly not guaranteed to be the requested size.
This is often inconvenient since the size of the returned thumbnail cannot be predicted. The django-thumbs
library solves this for square thumbnails by cropping the image to a square and then resizing it. However,
this only works for exact squares.
This function generalizes that approach to work for thumbnails of any aspect ratio. The returned thumbnail
is always exactly the requested size, and edges (left/right or top/bottom) are cropped off to adjust to
make sure the thumbnail will be the right size without distorting the image.

tmux cheatsheet

As configured in my dotfiles.

start new:

tmux

start new with session name:

@crtr0
crtr0 / client.js
Created June 8, 2012 17:02
A simple example of setting-up dynamic "rooms" for socket.io clients to join
// set-up a connection between the client and the server
var socket = io.connect();
// let's assume that the client page, once rendered, knows what room it wants to join
var room = "abc123";
socket.on('connect', function() {
// Connected, let's sign-up for to receive messages for this room
socket.emit('room', room);
});
@littlepea
littlepea / munin.rst
Last active June 8, 2024 15:42
Munin setup for monitoring Django on EC2 Ubuntu instance with nginx

This is a short tutorial on setting up munin to monitor your Django website on ec2.

We're gonna be using Nginx instead of apache here because it's more lightweight and popular between Django developers.

Step by step tutorial

1. Install munin

from django import http
from django.conf import settings
"""
Put this file in a directory called, eg, 'middleware,' inside your django
project. Make sure to create an __init__.py file in the directory so it can
be included as a module.
Set the values for
XS_SHARING_ALLOWED_ORIGINS
XS_SHARING_ALLOWED_METHODS
@joyrexus
joyrexus / README.md
Last active June 19, 2024 09:35 — forked from liamcurry/gist:2597326
Vanilla JS equivalents of jQuery methods

Sans jQuery

Events

// jQuery
$(document).ready(function() {
  // code
})
@osharim
osharim / Run django and nodejs running over nginx in the same server
Last active December 21, 2023 12:58
Nginx reverse proxy with Django & Node
#Django Config
server {
server_name domain.com;
access_log on;
location / {
proxy_pass http://127.0.0.1:8001;
@matheusho
matheusho / django_signals_slugify.py
Last active August 1, 2018 14:22
Django : Generate unique slug
# import signals and slugify
from django.db.models import signals
from django.template.defaultfilters import slugify
# function for use in pre_save
def yourmodel_pre_save(signal, instance, sender, **kwargs):
if not instance.slug:
slug = slugify(instance.attribute) # change the attibute to the field that would be used as a slug
new_slug = slug
@edouard-lopez
edouard-lopez / gulpfile.js
Created May 5, 2014 15:18
Gulp copy font-awesome files to dist/ directory
'use strict';
// Generated on 2014-04-14 using generator-leaflet 0.0.14
var gulp = require('gulp');
var open = require('open');
var wiredep = require('wiredep').stream;
// Load plugins
var $ = require('gulp-load-plugins')();
from django import http
from django.conf import settings
"""
Put this file in a directory called, eg, 'middleware,' inside your django
project. Make sure to create an __init__.py file in the directory so it can
be included as a module.
Set the values for
XS_SHARING_ALLOWED_ORIGINS
XS_SHARING_ALLOWED_METHODS