Skip to content

Instantly share code, notes, and snippets.

View oprypin's full-sized avatar

Oleh Prypin oprypin

View GitHub Profile
@oprypin
oprypin / diffcolor.py
Last active October 22, 2023 01:34
Diffs with syntax highlight
import difflib
import pygments
import pygments.lexers
import pygments.formatters
def read_file(fn):
with open(fn) as f:
return f.read()
@oprypin
oprypin / base.html
Created March 22, 2014 09:49
How Flask+Jinja2 templating should be done generally
<!DOCTYPE html>
<html>
<head>
{% block head %}
<title>{% block title %}Awesome website{% endblock %}</title>
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='style.css') }}"/>
{% endblock head %}
</head>
<body>
<header>
@oprypin
oprypin / gist:f2e1cd5f74d4809fbbc0
Created March 26, 2014 11:57
Flask current_user function to load the user only when needed
def current_user():
try:
return g.current_user
except RuntimeError:
return None
except AttributeError:
try:
g.current_user = db.query(User).get(session['user_id'])
except KeyError:
g.current_user = None
@oprypin
oprypin / analyze.py
Last active March 17, 2018 23:44
Analyzer for LYNE patterns
from collections import namedtuple, Counter
import urllib.request
Item = namedtuple('item', 'n l a b')
items = []
for line in urllib.request.urlopen('http://blaxpirit.pythonanywhere.com/lyne/text'):
line = line.strip().decode('utf-8')
n, l, a, b = line.split()
@oprypin
oprypin / lyne_cracked.py
Last active August 29, 2015 13:57
Run this to see LYNE's hidden message
# Perhaps read this first: http://steamcommunity.com/app/266010/discussions/0/558750717604246010/
from __future__ import print_function # Python 2 compatibility
from itertools import cycle
try:
from urllib.request import urlopen
except ImportError:
from urllib2 import urlopen # Python 2 compatibility
#include <iostream>
using namespace std;
struct Base {
void f() {
cout << "base" << endl;
}
void g() {
f();
@oprypin
oprypin / bot.py
Created December 16, 2014 15:05
Skype Bot that matches inconsistent number of brackets in received messages as a protest to eyeless emoticons ")))"
#!/usr/bin/env python2
import re
import unicodedata
import Skype4Py
emoticons = open('emoticons.txt').read().split()
emoticons_re = r'(' + '|'.join(re.escape(' '.join(e)).replace(' ', ' ?') for e in emoticons) + r')'
@oprypin
oprypin / csfml.diff
Last active August 29, 2015 14:12
API changes between SFML 2.1 and 2.2
git diff CSFML-2.1 CSFML-master | grep -vP '^([^-+]|. *//)' | sed -r 's/^[-+]{3} .+\///g' | uniq
Export.h
Listener.h
-CSFML_AUDIO_API void sfListener_setDirection(sfVector3f orientation);
+CSFML_AUDIO_API void sfListener_setDirection(sfVector3f direction);
+CSFML_AUDIO_API void sfListener_setUpVector(sfVector3f upVector);
+
+CSFML_AUDIO_API sfVector3f sfListener_getUpVector();
+
@oprypin
oprypin / 0001-Add-regex-replacement-using-results-of-calling-a-pro.patch
Last active August 29, 2015 14:13
Regular expression replacement using results of calling a procedure
From 6ae230f9c9809141deea110900a36242ac9256dc Mon Sep 17 00:00:00 2001
From: Oleh Prypin <[email protected]>
Date: Thu, 8 Jan 2015 00:09:07 +0200
Subject: [PATCH] Add regex replacement using results of calling a procedure
---
lib/impure/re.nim | 29 +++++++++++++++++++++++++++++
1 file changed, 29 insertions(+)
diff --git a/lib/impure/re.nim b/lib/impure/re.nim
@oprypin
oprypin / neg_ind.nim
Last active August 29, 2015 14:13
Replacement for negative indices
var s = "abcdef"
echo s[2 .. -3] # I suggest to remove this
# cd
proc `^`(x: int): int = assert false
template ex{`[]`(s, `..`(a, `^`(b)))}(s: expr{noSideEffect}, a, b: int): expr =
s[a .. s.len+b]
echo s[2 .. ^ -3] # Easy fix in code