Skip to content

Instantly share code, notes, and snippets.

@sjava
sjava / check_uwsgi.sh
Created June 21, 2018 07:45 — forked from SuneKjaergaard/check_uwsgi.sh
Small shell script to restart the uWSGI application when https://github.com/unbit/uwsgi/issues/1369 happens. Based on uWSGI server run by upstart
#!/bin/bash
line=$(tail -1 /var/log/myapp/myapp.uwsgi.log)
substr='uWSGI listen queue of socket'
if test "${line#*$substr}" != "$line"
then
#We're using upstart, could be easily adapted to fx systemd
# Adding a log statement to keep track of when this happens. Remember to create the monitor dir
/sbin/initctl restart myapp > /var/log/myapp/monitor/uwsgi-monitor.log 2>&1
echo "$(date) restarted myapp due to listen queue error" >> /var/log/myapp/monitor/uwsgi-monitor.log
@sjava
sjava / 256 colors.md
Created January 30, 2018 01:29 — forked from limingjie/256 colors.md
256 colors in putty, tmux/screen and vim

#256 colors in putty, tmux/screen and vim There is a detailed answer on stackoverflow. If you are looking for a short one, here it is.

  • putty

    Set Connection -> Data -> Terminal-type string to xterm-256color

  • tmux

Add this line to ~/.tmux.conf

@sjava
sjava / how-to-fix-tmux-fail.md
Created January 24, 2018 15:10 — forked from sv0/how-to-fix-tmux-fail.md
If tmux fails with an error "terminal open failed: missing or unsuitable terminal: rxvt-unicode-256color"

If tmux fails with an error terminal open failed: missing or unsuitable terminal: rxvt-unicode-256color

log in to your remote host and create .terminfo/r in your home directory:

mkdir .terminfo/r

copy terminal information file to remote machine:

scp /usr/share/terminfo/r/rxvt-unicode* remote.host:.terminfo/r/

@sjava
sjava / cropped_thumbnail.my
Created December 26, 2016 15:07 — forked from olooney/cropped_thumbnail.my
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.
<dom-module id="nyaovim-app">
<template>
<style>
html,body {
background: transparent;
}
@keyframes blink {
0% {
@sjava
sjava / build-git.sh
Created September 29, 2016 15:24 — forked from pescobar/build-git.sh
compile git with openssl instead of gnutls
#!/usr/bin/env bash
# Clear out all previous attempts
rm -rf "/tmp/source-git/"
# Get the dependencies for git, then get openssl
sudo apt-get install build-essential fakeroot dpkg-dev -y
sudo apt-get build-dep git -y
sudo apt-get install libcurl4-openssl-dev -y
mkdir -p "/tmp/source-git/"
@sjava
sjava / forms.py
Created August 17, 2016 14:28 — forked from rombr/forms.py
How to add custom fields order to WTForms
from collections import OrderedDict
# ...
class OrderFormMixin(object):
'''
To apply add to Meta 'order' iterable
'''
def __init__(self, *args, **kwargs):
super(OrderFormMixin, self).__init__(*args, **kwargs)

Sample service script for debianoids

Look at LSB init scripts for more information.

Usage

Copy to /etc/init.d:

# replace "$YOUR_SERVICE_NAME" with your service's name (whenever it's not enough obvious)
@sjava
sjava / cracking.md
Last active August 29, 2015 14:10 — forked from vertexclique/cracking.md

MacOS

Build 3059

MD5: 59bab8f71f8c096cd3f72cd73851515d

Rename it to: Sublime Text

Make it executable with: chmod u+x Sublime\ Text

@sjava
sjava / _form.html.erb
Created December 15, 2011 13:12 — forked from vjm/_form.html.erb
CRUD Devise Example
<%= form_for(@user) do |f| %>
<% if @user.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@user.errors.count, "error") %> prohibited this user from being saved:</h2>
<ul>
<% @user.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>