Skip to content

Instantly share code, notes, and snippets.

View pbojinov's full-sized avatar

Petar Bojinov pbojinov

View GitHub Profile
@allolex
allolex / gist:4564357
Last active December 11, 2015 07:09
Improved code for snapping photos when committing to a git repo
#!/bin/bash
function make_image_dir () {
TARGET_DIR=$1
if [ ! -d "${TARGET_DIR}" ]; then
mkdir "${TARGET_DIR}"
fi
}
function ignore_image_dir () {
@mgonto
mgonto / configuration.js
Created April 30, 2013 05:10
Restangular responseInterceptor
app.config(function(RestangularProvider) {
// First let's set listTypeIsArray to false, as we have the array wrapped in some other object.
RestangularProvider.setListTypeIsArray(false);
// Now let's configure the response extractor for each request
RestangularProvider.setResponseExtractor(function(response, operation, what, url) {
var newResponse;
// This is a get for a list
if (operation === "getList") {
// First the newResponse will be response.objects which is actually an array
@webhat
webhat / keeniolab.js
Created June 6, 2013 12:34
Keen.IO Resource Factory with Service Model
'use strict';
angular.module('keeniolab', ['ngResource']).
factory('KeenIO',function ($resource) {
var KeenIO = $resource('https://api.keen.io/3.0/projects/513a76812975164a4a000002/queries/:type',
{
api_key: 'api-key',
event_collection: 'read',
timezone: 7200
}, {
update: { method: 'PUT' }
@dpup
dpup / FastMutex.js
Last active July 28, 2016 07:53
Code snippet for mutual exclusion lock in javascript.
FastMutex.prototype.runInLock = function (callback, opt_context) {
this._setX()
if (!this._isLockAvailable()) {
this._retry(callback, opt_context)
return
}
this._setY()
const fetch = (url, params) => ({
type: 'FETCH',
url,
params,
});
const fetchMiddleware = fetchImplementation => store => next => action => {
if (action.type === 'FETCH') {
const { url, params } = action;
const token = store.getState().token;
@loren
loren / initial_asis_settings.json
Created October 28, 2014 17:30
Initial Elasticsearch settings
{
"settings": {
"index": {
"analysis": {
"char_filter": {
"ignore_chars": {
"type": "mapping",
"mappings": [
"'=>",
"\u2019=>",
@fosstrack
fosstrack / elasticsearch.custom.sort.py
Last active November 21, 2016 18:20 — forked from darklow/elasticsearch.custom.sort.py
Updated script to avoid org.elasticsearch.index.mapper.Uid.idFromUid which no longer works. Cast the doc['id'].value as needed to enable array look up. This is based on a comment by the original author elsewhere.
q = {
"query": {
"function_score": {
"boost_mode": "replace",
"query": {
"ids": {
"values": [
50,
80,
44,
@simenbrekken
simenbrekken / KeyboardShortcutsMixin.js
Created August 31, 2014 08:15
React Keyboard Shortcuts Mixin
'use strict';
var KEYS = {
enter: 13,
left: 37,
right: 39,
escape: 27,
backspace: 8,
comma: 188,
shift: 16,
@lbenitez000
lbenitez000 / boto_decimal_monkeypatch.py
Last active March 16, 2017 16:02
A monkey patch for boto's Decimal context to allow inexact and rounded representation of floats. Used to store any float in DynamoDB when inexactitude is allowed.
# Monkey patch Decimal's default Context to allow
# inexact and rounded representation of floats
import decimal
from boto.dynamodb.types import DYNAMODB_CONTEXT
# Inhibit Inexact Exceptions
DYNAMODB_CONTEXT.traps[decimal.Inexact] = 0
# Inhibit Rounded Exceptions
DYNAMODB_CONTEXT.traps[decimal.Rounded] = 0
@jamesonthecrow
jamesonthecrow / turicreate_not_hotdog_medium_post.py
Last active February 15, 2018 00:35
Code snippets for the Medium post on building Not Hotdog with Turi Create
import requests
import shutil
import os
def download_images(url_filename, out_directory, max_urls=None):
"""Download images from a file containing URLS.
The URL file must contain a single URL per line.
Args: