Skip to content

Instantly share code, notes, and snippets.

View dasdachs's full-sized avatar
🏠
Working from home

Jani Šumak dasdachs

🏠
Working from home
View GitHub Profile
@dasdachs
dasdachs / urls_from_css.py
Created March 17, 2016 07:14
Python - get URLs from CSS
def get_urls(css_file):
"""
Get all URLs from a CSS file with regex pattern matching.
URI's, like data URIs are ignored and URLs might be relative.
:param css_file: a string representing the CSS file (use open()
and read() or a request library to get the string)
:return: list with retrived urls
"""
@dasdachs
dasdachs / wagtall_save_image_from_shell.py
Created June 20, 2016 14:27
Save an image from the shell or programatically to Wagtail.
# Save an image from the shell or programatically to Wagtail
# If you are using a cutom Image model, please import your model
import os
from django.core.file import File
from wagtail.wagtailimages.models import Image
def save_image_to_wagtail(image):
"""
@dasdachs
dasdachs / csv_to_flask.py
Created July 24, 2016 13:14
Upload, read and save the content of a csv file to your model
#!/usr/bin/env python
from io import TextIOWrapper
import csv
from flask import Flask, request, redirect, url_for
from flask_sqlalchemy import SQLAlchemy
# Create Flaskk app, config the db and load the db object
# http://flask-sqlalchemy.pocoo.org/2.1/quickstart/#a-minimal-application
@dasdachs
dasdachs / sicris_scraper.py
Last active May 30, 2017 16:04
A simple scraper for sicris.si
# -*- coding: UTF-8 -*-
#! usr/bin/python3
__author__ = "Jani Šumak <jani.sumak@gmail.com>"
__version__ = "1.0"
import datetime
import logging
import json
import time
@dasdachs
dasdachs / start.sh
Last active March 27, 2017 07:35
Ubuntu server setup script
#! /usr/bin/env bash
#
# in progress
# Install Caddy webserver
curl https://getcaddy.com | bash -s git,cors,hugo
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<script id="jsbin-javascript">
@dasdachs
dasdachs / index.html
Last active September 22, 2017 14:07
Fakebook page | Smartninja
<!DOCTYPE html>
<html>
<head lang="sl">
<meta charset="UTF-8">
<meta name="description" content="Janis Fakebook profile">
<meta name="keywords" content="me, about, interests, fakebook">
<meta name="author" content="Jani Šumak">
<title>Jani Šumak | Fakebook</title>
@dasdachs
dasdachs / index.html
Last active September 26, 2017 18:09
SM_2: HTML + CSS
<!DOCTYPE html>
<html>
<head lang="sl">
<meta charset="UTF-8">
<meta name="description" content="Janis Fakebook profile">
<meta name="keywords" content="me, about, interests, fakebook">
<meta name="author" content="Jani Šumak">
<title>Jani Šumak | Fakebook</title>
VAR = line:line* { return line; } // Return array of arrays with elements :D
start = ws "{{" ws
end = ws "}}" ws
ws "whitespace"
= s:[ \t\r]*
n "newline"
= n:"\n"*
@dasdachs
dasdachs / poor_mans_csv_parser.py
Created August 22, 2018 09:15
Poor mans csv parser
def poor_mans_csv_parser(text, delimiter=',', quote='"'):
assert isinstance(text, list), "At the momment we can not process strings."
parsed_text = []
for line in text:
line = list(line)
parsed_line = []
current = ''
quoted = False
while line: