Skip to content

Instantly share code, notes, and snippets.

View softMaina's full-sized avatar
🎯
Looking for work

softMaina softMaina

🎯
Looking for work
  • Nairobi, Kenya
  • 00:23 (UTC +03:00)
View GitHub Profile
@softMaina
softMaina / compress-pdf-with-gs.md
Created April 1, 2021 08:45 — forked from guifromrio/compress-pdf-with-gs.md
Compress PDF files with ghostscript

This can reduce files to ~15% of their size (2.3M to 345K, in one case) with no obvious degradation of quality.

ghostscript -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/printer -dNOPAUSE -dQUIET -dBATCH -sOutputFile=output.pdf input.pdf

Other options for PDFSETTINGS:

  • /screen selects low-resolution output similar to the Acrobat Distiller "Screen Optimized" setting.
  • /ebook selects medium-resolution output similar to the Acrobat Distiller "eBook" setting.
  • /printer selects output similar to the Acrobat Distiller "Print Optimized" setting.
  • /prepress selects output similar to Acrobat Distiller "Prepress Optimized" setting.
@softMaina
softMaina / query.sql
Created October 24, 2020 18:53 — forked from ramiroaznar/query.sql
How to find duplicate values with PostgreSQL
select * from table t1
where (select count(*) from table t2
where t1.field = t2.field) > 1
order by field
@softMaina
softMaina / onlinenowMiddelware.py
Created September 24, 2020 13:44 — forked from agusmakmun/onlinenowMiddelware.py
django online users, usage: {{ request.online_now }} or {{ request.online_now_ids }}, usage: https://python.web.id/blog/django-count-online-users/
from django.conf import settings
from django.core.cache import cache
from django.contrib.auth.models import User
from django.utils.deprecation import MiddlewareMixin
ONLINE_THRESHOLD = getattr(settings, 'ONLINE_THRESHOLD', 60 * 15)
ONLINE_MAX = getattr(settings, 'ONLINE_MAX', 50)
def get_online_now(self):
return User.objects.filter(id__in=self.online_now_ids or [])