Skip to content

Instantly share code, notes, and snippets.

View abele's full-sized avatar

Jānis Ābele abele

View GitHub Profile
@abele
abele / amazon-content-list-export.js
Last active May 17, 2016 17:40
Export Amazon content list to CSV file
/**
var bookView = 'https://www.amazon.com/mn/dcw/myx.html#/home/content/booksAll/dateDsc/';
*/
function downloadContentCSV() {
var lis = [].slice.call(document.querySelector('.nav.nav-grid.ui-grid').querySelectorAll('li')),
csvContent = 'data:text/csv;charset=utf-8,';
lis.forEach(function (el, i) {
var title = el.querySelector('#title' + i).innerHTML,
author = el.querySelector('#author' + i).innerHTML,
@abele
abele / test_map_contract.py
Created September 20, 2015 17:13
Abstract Test or Contract Test with pytest
import pytest
def square(num):
return num * num
def recursive_map(f, _list):
"""Recusive map implementation."""
if not _list:
@abele
abele / viewable_dates.js
Last active September 19, 2015 08:38
JavaScript code snippet code review and refactoring. Snippet DID NOT have tests. NO guarantee that changes doesn't break it.
set_viewable_dates: function (task, month_to_check, now) {
/*
it will set:
start_to_show, end_to_show (and postponed_to_show) | <-- moment() dates |
variables to be used in list template,
so that original start, end (and postponed) values of a task wouldn't be affected
if a tasks start, end, postponed values span over month_to_check,
start, end, postponed will be reduced to only contain values which cover month_to_check
so that start_to_show <= month_to_check >= end_to_show
@abele
abele / GiftExchangePairGenerator.py
Created August 26, 2015 15:33
idiomatic python
# -*- coding: utf-8 -*-
import random
def getRandomPerson(ppl):
return ppl[random.randint(0,len(ppl)-1)]
def good_pair(ignore_ppl, chosen1, chosen2):
for pair in ignore_ppl:

Keybase proof

I hereby claim:

  • I am abele on github.
  • I am abele (https://keybase.io/abele) on keybase.
  • I have a public key whose fingerprint is 795B A0E1 6F1B 751B 6860 F91F B067 98E2 1D27 99BE

To claim this, I am signing this object:

@abele
abele / fabfile.py
Last active August 29, 2015 14:11
Fabfile used in combination with Salt-Stack
from fabric.api import sudo, task, env, local, settings
from fabric.contrib.files import upload_template
from fabric.contrib.project import upload_project
import os
salt_task = hosts('@'.join([os.environ['AS_MASTER_USER'], os.environ['AS_MASTER_HOST']]))
"""Decorator to specify Salt-Stack master user and host."""
import re
from functools import reduce
def test_handles_words_with_vowels():
assert pig_latin('egg') == 'eggway'
def test_handles_words_starting_with_consonat():
assert pig_latin('happy') == 'appyhay'
import re
def test_with_with_vowels_ends_with_hey():
assert pig_latin('egg') == 'eggway'
def test_handle_words_with_consonants():
assert pig_latin('happy') == 'appyhay'
@abele
abele / robot.js
Created December 5, 2012 12:13 — forked from Shipow/robot.js
Shipow#001
var Robot = function(robot) {
robot.rotateCannon(-90);
};
Robot.prototype.onIdle = function(ev) {
var robot = ev.robot;
robot.ahead();
//i'll add a clone but i need to refactor collision
//robot.clone();
};