Skip to content

Instantly share code, notes, and snippets.

View ydm's full-sized avatar

Йордан Миладинов ydm

  • Sofia, Bulgaria
View GitHub Profile
@ydm
ydm / permutation.c
Created June 29, 2012 09:06
Generate next permutation in lexicographic order
int
num_digits (int n)
{
int r;
for (r = 1, n /= 10; n != 0; n /= 10)
r++;
return r;
}
@ydm
ydm / django_header_view_decorators.py
Last active July 19, 2020 01:41
This file includes two Django view decorators `header` and `headers` that provide an easy way to set response headers. Also, because I have to work with a lot of cross domain requests, I include few shortcuts for convenience to set the Access-Control-Allow-Origin header appropriately.
# -*- coding: utf-8 -*-
from functools import wraps
from django.utils.decorators import available_attrs
def header(name, value):
# View decorator that sets a response header.
#
@ydm
ydm / pycurl_post_string_as_file.py
Last active December 14, 2015 12:38
Issue an HTTP POST request to upload a string as file using libcurl and pycurl. Tested against Python 2.7.3 and libcurl 7.29.0.
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
#
# Issue an HTTP POST request to upload a string as file using libcurl
# and pycurl.
#
# vars.php
# <?php
@ydm
ydm / klist_example.c
Last active October 31, 2016 07:42
I'm too stupid for this
typedef struct {
int val;
struct klist_node node;
} knode_t;
/* Not the wisest way of doing it for sure. */
knode_t *
my_klist_first (struct klist *list)
{
struct klist_iter iter;
getCookie = (name) ->
if document.cookie and document.cookie.length > 0
cookies = ($.trim(i) for i in document.cookie.split(';'))
for cookie in cookies
if cookie.substring(0, name.length + 1) == "#{name}="
val = decodeURIComponent cookie.substring(name.length + 1)
return val
return null
@ydm
ydm / unicode_pprint_and_pformat.py
Created April 11, 2013 21:20
Variant of pprint and pformat functions that do not escape unicode characters.
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from StringIO import StringIO
import pprint as pprint
import sys
# Original idea: http://softwaremaniacs.org/forum/python/25696/
@ydm
ydm / refresh_firefox.sh
Created May 14, 2013 10:13
Refresh Firefox from the command line
xdotool search --name Firefox key --window %@ F5
@ydm
ydm / python-run.el
Created July 19, 2013 15:44
Send current buffer to a freshly made python shell
(defun y:python-run ()
(interactive)
(let* ((dedicated-proc-name (python-shell-get-process-name t))
(dedicated-proc-buffer-name (format "*%s*" dedicated-proc-name))
(dedicated-running (comint-check-proc dedicated-proc-buffer-name)))
;; If there's already a python shell running for this buffer, kill it
(when dedicated-running
(let* ((process (python-shell-get-or-create-process))
(buffer (process-buffer process)))
(set-process-query-on-exit-flag process nil)
@ydm
ydm / qxttooltip.py
Last active December 22, 2015 03:39
Python translation of Qxt (Qt extension framework) tooltips. More information about LibQxt and QxToolTip refer to http://dev.libqxt.org/libqxt/wiki/Home
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
from __future__ import print_function
from __future__ import unicode_literals
import sys
from PyQt4 import QtCore, QtGui
from PyQt4.QtCore import Qt
@ydm
ydm / version.py
Last active March 13, 2018 12:49
Version field for Django models
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import re
from django import forms
from django.core import exceptions
from django.db import models
from south.modelsinspector import add_introspection_rules