Skip to content

Instantly share code, notes, and snippets.

@davorbadrov
davorbadrov / extract_worklog.js
Last active Mar 11, 2019
Extracts working hours for JIRA
View extract_worklog.js
// The worklog has to be open in timesheets and
// Developer Console must be open with Right-click > Inspect so the source maps take effect.
// Paste and run the code inside the Console.
// Note: Tested only on Chrome.
_issueTitles = document.querySelectorAll('.tempo-issue-table-td-issue [title]')
_issueDescriptions = document.querySelectorAll('.tempo-issue-table-td-comment [title]')
_workedHours = document.querySelectorAll('.tempo-issue-table-td-worked [title]')
_log = ''
for (let i = 0; i < _issueTitles.length; i++) {
@davorbadrov
davorbadrov / .editorconfig
Created May 6, 2018
Editor config for Javascript projects
View .editorconfig
root = true
[*.{js,json,yaml}]
indent_style = space
indent_size = 2
trim_trailing_whitespace = true
insert_final_newline = true
@davorbadrov
davorbadrov / getTimezone.js
Last active Oct 5, 2017
Google Timezone API
View getTimezone.js
/**
* Gets timezone info from Google's Timezone API
* based on passed latitude and longitude.
*/
const request = require('request');
const API_KEY = '...';
function getTimezone({latitude, longitude}) {
const timestamp = Math.floor(new Date().getTime() / 1000);
const url = `https://maps.googleapis.com/maps/api/timezone/json?location=${latitude},${longitude}&timestamp=${timestamp}&key=${API_KEY}`;
@davorbadrov
davorbadrov / readJson.js
Created May 9, 2017
Read JSON file in frontend
View readJson.js
// jsonFile can be files[0] from the change event on the input
// it returns a Promise which resolves as JSON content
// or rejects and outputs why it failed
export function readJSON(jsonFile) {
return new Promise((resolve, reject) => {
const reader = new FileReader();
reader.onload = event => {
try {
const jsonContent = JSON.parse(reader.result);
@davorbadrov
davorbadrov / form_examples.js
Created Dec 6, 2016
React (controlled) form elements
View form_examples.js
// SELECT
<select value={this.state.value} onChange={this.handleChange}>
<option value="grapefruit">Grapefruit</option>
<option value="lime">Lime</option>
<option value="coconut">Coconut</option>
<option value="mango">Mango</option>
</select>
// TEXTAREA
<textarea value={this.state.value} onChange={this.handleChange} />
@davorbadrov
davorbadrov / index.js
Last active Oct 27, 2016
Tag and Autocomplete combined - Using Awesomeplete + Taggle libs together to create an autocompleting tag input
View index.js
// Suppose we have a following HTML element in page:
// <div id="tags" />
const tagsInput = new Taggle(document.querySelector('#tags'), {
allowDuplicates: false,
preserveCase: true,
attachTagId: true,
// tags: preexistingTagsToPrefilTheinput,
// onTagAdd: (e, tag) => {
// console.log('adding tag', tag);
@davorbadrov
davorbadrov / find_multiple.sql
Last active Aug 6, 2017
SQL - Find multiple entries inside a table for given values.
View find_multiple.sql
# find multiple entries for a certain fields
select count(*), field1, field2 from some_table group by field1, field2 having count(*) > 1;
@davorbadrov
davorbadrov / index.js
Created Dec 23, 2015
Simple React/Redux example, taken from Dan Abramov's Redux tutorial series on Egghead.io
View index.js
import React from 'react';
import ReactDOM from 'react-dom';
import expect from 'expect';
import { createStore } from 'redux';
/**
* The reducer function which takes a state and action,
* returns the new state
*
* @param {Number} state old state from the store
View PromisifyAll
var Promise = require('bluebird');
...
// Transforms node based callbacks into methods that return Promises
Promise.promisifyAll(Awesomify);
Promise.map(jsonArray, function (jsonItem) {
return Awesomify.transformAsync(jsonItem);
})
.then(function(transformedResults) {
@davorbadrov
davorbadrov / index.html
Created Nov 4, 2015
Responsive elements with dynamic content using table styling.
View index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JS Bin</title>
<link rel="stylesheet" href="main.css">
</head>
<body>
<div class="bar-container">
<div class="bar"></div>
You can’t perform that action at this time.