Skip to content

Instantly share code, notes, and snippets.

View crooksey's full-sized avatar

Luke Crooks crooksey

  • Hampshire, UK
View GitHub Profile
@crooksey
crooksey / gist:3425145
Created August 22, 2012 12:35
Fixing broken primary keys on postgres
// Login to psql and run the following
// What is the result?
SELECT MAX(id) FROM your_table;
// Then run...
// This should be higher than the last result.
SELECT nextval('your_table_id_seq');
// If it's not higher... run this to try and fix it. (run a quick pg_dump first...)
SELECT setval('your_table_id_seq', (SELECT MAX(id) FROM your_table)+1);
from pyramid.config import Configurator
from pyramid.authorization import ACLAuthorizationPolicy
from pyramid.security import Allow
from pyramid.security import Deny
from pyramid.security import Everyone, ALL_PERMISSIONS
from pyramid.security import (
Authenticated,
Everyone,
@crooksey
crooksey / material.module.ts
Created September 27, 2018 09:42
material.module.ts
import { NgModule } from '@angular/core';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { CdkTableModule } from '@angular/cdk/table';
import {
MatAutocompleteModule,
MatButtonModule,
MatButtonToggleModule,
MatCardModule,
MatCheckboxModule,
MatChipsModule,
#!/bin/sh
## Service for traccar.
# PROVIDE: traccar
# REQUIRE: DAEMON
# BEFORE:
# KEYWORD: shutdown
# Add the following lines to /etc/rc.conf to enable `traccar':
+ [ -r /etc/rc.conf ]
+ . /etc/rc.conf
+ rc_debug=YES
+ traccar_enable=YES
+ traccar_root=/usr/local/traccar
+ traccar_user=root
+ traccar_java=/usr/local/openjdk7-jre/bin/java
+ sourced_files=:/etc/rc.conf::/etc/rc.conf.local:
+ [ -r /etc/rc.conf.local ]
+ _rc_conf_loaded=true
@crooksey
crooksey / traccar.sh
Created August 20, 2018 11:46
Traccar rc.d
#!/bin/sh
#
# PROVIDE: traccar
# REQUIRE: DAEMON
# BEFORE:
# KEYWORD: shutdown
# Add the following lines to /etc/rc.conf to enable `traccar':
#
from celery import Celery
from celery.schedules import crontab
from pyramid_mailer.message import Message
from intranet_backend_api.celery_bundle.celery_settings import mailer
# Define app
app = Celery()
## Broker settings.
broker_url = 'amqp://app_rmq:pass@localhost:5672/intranet'
# Set timezone, for DST
class TAAbsence(BaseRW):
__tablename__= 'ta_absences'
id = Column(Integer, primary_key=True)
user_id = Column(Integer, ForeignKey('ta_users.id'), nullable=False)
start_date = Column(Date, nullable=False)
end_date = Column(Date, nullable=False)
# so an example TAAbsence
@crooksey
crooksey / plot_map.py
Last active December 7, 2017 08:59
Plotting map using bounding box
central_lat = sum(lats)/len(lats)
central_lng = sum(lngs)/len(lngs)
bbox = BoundingBox(coords)
map = Basemap(
llcrnrlon=bbox.minx,llcrnrlat=bbox.miny,
urcrnrlon=bbox.maxx,urcrnrlat=bbox.maxy,
resolution='i', projection='tmerc',
lat_0 = central_lat, lon_0 = central_lng)
{
"status": "success",
"total_travel_time": 31.983334,
"total_idle_time": 0,
"num_unserved": 0,
"unserved": null,
"solution": {
"vehicle_1": [
{
"location_id": "depot",