Skip to content

Instantly share code, notes, and snippets.

View pbojinov's full-sized avatar

Petar Bojinov pbojinov

View GitHub Profile
@pbojinov
pbojinov / es_proxy.js
Created February 9, 2018 22:00 — forked from rveitch/es_proxy.js
Example Elasticsearch Proxy for Node.js
var express = require('express');
var request = require('request');
var app = express();
var port = Number(process.env.PORT || 3000);
var apiServerHost = (process.env.ELASTIC_URL || 'http://127.0.0.1:9200')
// Listen for requests on all endpoints
app.use('/', function(req, res, body) {
// short-circuit favicon requests for easier debugging
async function makePizza(sauceType = 'red') {
let dough = await makeDough();
let sauce = await makeSauce(sauceType);
let cheese = await grateCheese(sauce.determineCheese());
dough.add(sauce);
dough.add(cheese);
return dough;
var DateTime = luxon.DateTime;
var then = DateTime.fromISO('2017-07-04T15:16:14.000Z');
var now = DateTime.local();
var diff = then.diff(now, 'days');
diff.toObject(); // => {days: 150.30536171296296} || diff.as('days') => 150
@pbojinov
pbojinov / convert_wav_to_mp3.sh
Created October 20, 2017 18:44
shell script to convert all wav files in the current working directory to mp3 files using ffmpeg
#!/bin/bash
FILES=*.wav
for f in $FILES
do
# echo "Processing ${f/.wav/.mp3} file..."
echo "Processing $f file..."
ffmpeg -i "$f" -codec:a libmp3lame -qscale:a 0 "${f/.wav/.mp3}"
# take action on each file. $f store current file name
# cat $f
done
@pbojinov
pbojinov / country_states.json
Created October 2, 2017 21:47
A list of all countries in the world with their corresponding provinces
[
{
"name": "Afghanistan",
"iso_code": "AF",
"provinces": [
{
"name": "Badakhshan",
"code": "BDS"
},
{
@pbojinov
pbojinov / US Zip Codes from 2013 Government Data
Created May 22, 2017 22:32 — forked from erichurst/US Zip Codes from 2013 Government Data
All US zip codes with their corresponding latitude and longitude coordinates. Comma delimited for your database goodness. Source: http://www.census.gov/geo/maps-data/data/gazetteer.html
This file has been truncated, but you can view the full file.
ZIP,LAT,LNG
00601,18.180555, -66.749961
00602,18.361945, -67.175597
00603,18.455183, -67.119887
00606,18.158345, -66.932911
00610,18.295366, -67.125135
00612,18.402253, -66.711397
00616,18.420412, -66.671979
00617,18.445147, -66.559696
@pbojinov
pbojinov / seconds_since_epoch.js
Last active April 26, 2017 20:01
seconds since epoch
function seconds_since_epoch() {
return Math.floor( Date.now() / 1000 )
}
epoch_time = seconds_since_epoch();
@pbojinov
pbojinov / list_intersections.py
Created April 19, 2017 22:44
List Intersections
a = [1,2,3]
b = [1,2,3,4,5]
x = list(set(b) - set(a))
y = list(set(b) - set(b).intersection((set(a))))
print x == y
@pbojinov
pbojinov / debug.js
Last active May 16, 2018 12:50
Debugging Javascript
try {
doSomething();
} catch(e) {
window.open('http://stackoverflow.com/search?q=[js] +' + e.message);
}
// or...
window.onError = function(e) {
window.open('http://stackoverflow.com/search?q=[js] +' + e.message);
});
@pbojinov
pbojinov / Icon.jsx
Created March 22, 2017 19:44
Reusable PNG Icons in React
import React, { PropTypes } from "react";
const Icon = props => {
const styles = {
img: {
width: `${props.size}`,
height: `${props.size}`
}
};
return <img style={styles.img} src={props.icon} />;