Skip to content

Instantly share code, notes, and snippets.

View maksbotan's full-sized avatar

Maxim Koltsov maksbotan

View GitHub Profile
@maksbotan
maksbotan / gist:2587517
Created May 3, 2012 17:40
Minimal test case for github auth api
>>> import json, urllib2
>>> data = {"scopes": ["gist"], "note": "pgist client"}
>>> j_req = json.dumps(data)
>>> req = urllib2.Request("https://api.github.com", data=j_req)
>>> resp = urllib2.urlopen(req)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib64/python2.7/urllib2.py", line 126, in urlopen
return _opener.open(url, data, timeout)
File "/usr/lib64/python2.7/urllib2.py", line 406, in open
#!/usr/bin/env python
import json, urllib2, base64
from xdg import BaseDirectory as basedir
from argparse import ArgumentParser
import os.path, sys, getpass
class AuthError(Exception): pass
def pgist_request_helper(uri, data, basic_auth="", auth_token=""):
#!/usr/bin/env python
import json, urllib2, base64
from xdg import BaseDirectory as basedir
from argparse import ArgumentParser
import os.path, sys, getpass
class AuthError(Exception): pass
def pgist_request_helper(uri, data, basic_auth="", auth_token=""):
#!/usr/bin/env python
import json, urllib2, base64
from xdg import BaseDirectory as basedir
from argparse import ArgumentParser
import os.path, sys, getpass
class AuthError(Exception): pass
def pgist_request_helper(uri, data, basic_auth="", auth_token=""):
(define (empty_list selector)
(selector '() '() #t)
)
(define (prepend el lst)
(lambda (selector)
(selector el lst #f)
)
)
@maksbotan
maksbotan / Groebner.hs
Created April 18, 2013 18:04
Source code for Groebner bases implementation in Haskell
import Data.List (intercalate, foldl')
data Monom c a = M c [a] deriving (Eq)
newtype Polynom c a = P [Monom c a] deriving (Eq)
instance (Eq c, Ord a) => Ord (Monom c a) where
compare (M _ asl) (M _ asr) = compare asl asr
instance (Show a, Show c, Num a, Num c, Eq a, Eq c) => Show (Monom c a) where
haskell-lsp:Starting up server ...
2018-09-07 11:49:18.303525648 [ThreadId 4] - ---> {"jsonrpc":"2.0","method":"initialize","params":{"capabilities":{"textDocument":{"completion":{"completionItem":{"snippetSupport":false}}},"workspace":{"applyEdit":true,"didChangeWatchedFiles":{"dynamicRegistration":true}}},"processId":31802,"rootPath":"/home/maks/Projects/SRK/ariadne","rootUri":"file:///home/maks/Projects/SRK/ariadne","trace":"off"},"id":47}
2018-09-07 11:49:18.303819425 [ThreadId 4] - haskell-lsp:initializeRequestHandler: setting current dir to project root:/home/maks/Projects/SRK/ariadne
2018-09-07 11:49:18.304185589 [ThreadId 6] - <--2--{"result":{"capabilities":{"textDocumentSync":{"openClose":true,"change":2,"willSave":false,"willSaveWaitUntil":false,"save":{"includeText":false}},"documentRangeFormattingProvider":true,"documentHighlightProvider":true,"executeCommandProvider":{"commands":["490:applyrefact:applyOne","490:applyrefact:applyAll","490:applyrefact:lint","490:base:version","490:base:plugins","4
@maksbotan
maksbotan / 1_readme.md
Created December 8, 2019 13:33
GHC bug with TemplateHaskell + DuplicateRecordFields

This is a minimal reproducing example for bug in GHC. It is observed in 8.6.3 (Stack LTS-13.6), 8.6.5 (nix) and 8.8.1 (nix).

$ ghc Exp.hs -ddump-splices
[1 of 2] Compiling TH               ( TH.hs, TH.o )
[2 of 2] Compiling Exp              ( Exp.hs, Exp.o )
Exp.hs:11:1-10: Splicing declarations make ''Bar ======>

Exp.hs:11:1: error:
@maksbotan
maksbotan / enums.md
Created December 30, 2019 07:19
Generic валидация

Валидация enum'ов во вложенных структурах

Про этот файл

Это Literate Haskell файл. Вот как загрузить его в ghci:

$ stack --resolver=lts-13.6 install markdown-unlit
$ stack --resolver=lts-13.6 ghci enums.md --package aeson --package validation --package semigroups --package containers --package lens --package generic-lens --ghci-options='-pgmL markdown-unlit'
@maksbotan
maksbotan / val.py
Created February 6, 2020 05:57
Example of type-level validation in python
from dataclasses import dataclass
from typing import Generic, Optional, TypeVar
class Raw:
pass
class Valid:
pass