Skip to content

Instantly share code, notes, and snippets.

@jacobg
jacobg / KeyMultiselect.vue
Created March 1, 2019 14:55
Extensions for the vue-multiselect component
<template>
<multiselect
v-bind="$attrs"
v-on="listeners"
:value="completeValue"
:options="options"
:track-by="trackBy"
:taggable="taggable"
@tag="addTag"
class="key-multiselect"
@jacobg
jacobg / IndexedCollectionTest.java
Last active September 22, 2016 15:45
Unit test demonstrating issue removing item with mutated indexable value
package com.googlecode.cqengine;
import com.googlecode.cqengine.attribute.SimpleAttribute;
import com.googlecode.cqengine.index.navigable.NavigableIndex;
import com.googlecode.cqengine.index.unique.UniqueIndex;
import com.googlecode.cqengine.quantizer.DoubleQuantizer;
import com.googlecode.cqengine.query.Query;
import com.googlecode.cqengine.query.option.QueryOptions;
import com.googlecode.cqengine.resultset.ResultSet;
from django.conf import settings
from django.core.exceptions import ImproperlyConfigured
from django.db import connection, models
from django.db.models import permalink, get_model
from django.utils.translation import ugettext_lazy as _
from django_extensions.db.fields import AutoSlugField
from django_extensions.db.models import TimeStampedModel
from organizations.managers import OrgManager, ActiveOrgManager
@jacobg
jacobg / monkey_patch.py
Last active December 29, 2015 00:39
The purpose of this monkey patch is to support writable fields using dotted source in Django Rest Framework. It based on the following fork which began the implementation, but left out a few details: https://github.com/craigds/django-rest-framework/compare/writable-dotted-field-source
#
# Based on this patch: https://github.com/craigds/django-rest-framework/compare/writable-dotted-field-source
# The purpose of this patch is to support writable fields using dotted source. It lets you do stuff like this:
# class UserProfileSerializer(ModelSerializer):
#
# user = PrimaryKeyRelatedField(read_only=True)
#
# active = BooleanField(source='user.is_active')
# first_name = CharField(source='user.first_name')
# last_name = CharField(source='user.last_name')
@jacobg
jacobg / Earliest time to go to mikveh on Rosh Hashanah
Last active October 2, 2016 15:34
For 02-Oct-2016 in Baltimore. Sunrise/set times from myzmanim.com
from datetime import date, datetime, time, timedelta
today= date.today()
sunrise = datetime.combine(today, time(7,3,56))
sunset = datetime.combine(today, time(17,46,35))
dawn = sunrise - timedelta(minutes=72)
dusk = sunset + timedelta(minutes=72)
earliest_time = min(dawn + (dusk-dawn)*5/12, sunrise + (sunset-sunrise)*5/12)
print('Earliest time = %s' % earliest_time.isoformat())
@jacobg
jacobg / gist:5686133
Last active December 17, 2015 22:59
Fareclock API sample for C#
using System;
using System.Net.Http;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
string token = "{{ MY API KEY }}";
@jacobg
jacobg / gist:5685574
Created May 31, 2013 14:59
Fareclock API sample for Python
from httplib import HTTPSConnection
from urllib import urlencode
token = '{{ MY API KEY }}'
params = {
'from': '2013-05-31',
'to': '2013-05-31',
#'paylocation': 0,
#'clocklocation': 0,
#'employee': 0,
@jacobg
jacobg / gist:5684875
Last active December 17, 2015 22:49
Fareclock API sample for NodeJS
var Https = require('https'),
Querystring = require('querystring'),
result = [],
token = '{{ MY API KEY }}',
params = {
'from': '2013-05-31',
'to': '2013-05-31',
//'paylocation': 0,
//'clocklocation': 0,
//'employee': 0,
@jacobg
jacobg / gist:5567886
Created May 13, 2013 12:11
Django Html template for migrate sample
<html>
<head>
{% if next_url != None %}
<meta http-equiv="refresh" content="0;url={{ next_url }}"/>
{% endif %}
</head>
<body>
<h3>Queue tasks for {{ task_name }}</h3>
<ul>
<li>Started at: {{ item_id }}</li>
@jacobg
jacobg / gist:5567873
Last active December 17, 2015 06:48
Example migrate script for Django
'''
Created on Oct 29, 2012
@author: jacobg
'''
from django.contrib.auth.decorators import login_required
from django.shortcuts import render_to_response
from django.template import RequestContext
from django.views.decorators.http import require_GET