Skip to content

Instantly share code, notes, and snippets.

View Bajena's full-sized avatar
🎩
Working on stuff

Jan Bajena Bajena

🎩
Working on stuff
View GitHub Profile
@Bajena
Bajena / GetData.gs
Last active June 23, 2018 20:50
Fetch recently played tracks from Spotify API using Google Script
function fetchPlays(startDate, endDate) {
var headers = {
Authorization: 'Bearer ' + getOAuthService().getAccessToken()
}
var start = new Date(startDate).getTime();
var end = new Date(endDate).getTime();
var url = 'https://api.spotify.com/v1/me/player/recently-played?before=' + end;
var data = [];
@Bajena
Bajena / Oauth.gs
Created June 23, 2018 19:16
Google script functions for performing simple Spotify Oauth flow
var oauth = {};
/** @const */
oauth.OAUTH_CLIENT_ID = 'OAUTH_CLIENT_ID';
/** @const */
oauth.OAUTH_CLIENT_SECRET = 'OAUTH_CLIENT_SECRET';
/**
* This builds an OAuth2 service for connecting to Spotify
@Bajena
Bajena / test.py
Created October 23, 2017 19:55
Sublime unit testing
import sublime
import sys
from unittest import TestCase
class TestNegateSentence(TestCase):
def setUp(self):
self.view = sublime.active_window().new_file()
# make sure we have a window to work with
s = sublime.load_settings("Preferences.sublime-settings")
s.set("close_windows_when_empty", False)
@Bajena
Bajena / sentence_negator.py
Created October 23, 2017 19:29
Class for negating present simple 3rd person sentences
class SentenceNegator:
IRREGULAR_ES_VERB_ENDINGS = ["ss", "x", "ch", "sh", "o"]
CONSONANTS = ['a', 'e', 'i', 'o', 'u', 'y']
def negate(self, sentence):
# is
if sentence.find("isn't") > -1:
return sentence.replace("isn't", "is")
if sentence.find("isn\\'t") > -1:
@Bajena
Bajena / find_quotes.py
Created October 22, 2017 20:53
Finds quoted sentence in python
def find_quotes(self):
quotes_regex = r'(\".*?\"|((?<!\\)\'.*?(?<!\\)\'))'
iterator = re.finditer(quotes_regex, self.current_line())
for match in iterator:
quote_span = match.span()
region = sublime.Region(quote_span[0] + self.current_line_start(), quote_span[1] + self.current_line_start())
if region.contains(self.cursor_position):
return (quote_span[0], quote_span[1])
@Bajena
Bajena / memory_leak_fix.js
Last active September 23, 2017 14:31
Memory leak fix
function checkMaxPresent() {
if (numbers[MAX_NUMBER]) {
numbers[MAX_NUMBER].css('background-color', 'red');
stop();
alert('SUCCESS');
return;
}
$('#numbers').html('');
numbers = {}; // usuwa referencje do niepotrzebnych div-ów
@Bajena
Bajena / memory_leak.js
Last active September 23, 2017 13:49
Simple jQuery memory leak
const MAX_NUMBER = 10000000;
var numbers = {};
var interval = null;
function getRandomInt(min, max) {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min + 1)) + min;
}
@Bajena
Bajena / function_breakpoints.js
Last active July 4, 2017 21:02
Function breakpoints - example
function myFunction() {
console.log('my func');
}
setInterval(function() {
var x = getRandomInt(0, 1);
if (x == 0) {
myFunction();
}
@Bajena
Bajena / xhr_breakpoints.js
Created July 4, 2017 20:02
XHR breakpoints demo
setInterval(function() {
var x = getRandomInt(0, 100);
$('#numbers').append(x).append("<br/>");
}, 1000);
setInterval(function() {
fetch('https://www.random.org/integers/?num=1&min=0&max=100&col=1&base=10&format=plain&rnd=new').then(function(response){
return response.text();
}).then(function(number) {
$('#numbers').prepend("<br/>").prepend(number);
@Bajena
Bajena / breakpoints_interval.js
Created July 4, 2017 19:23
DOM breakpoints demo
setInterval(function() {
var x = getRandomInt(0, 100);
$('#numbers').append(x).append("<br/>");
}, 1000);
setInterval(function() {
var x = getRandomInt(101, 200);
$('#numbers').prepend("<br/>").prepend(x);
}, 2000);