Skip to content

Instantly share code, notes, and snippets.

View kwilcox's full-sized avatar
🎯
ABC

Kyle Wilcox kwilcox

🎯
ABC
View GitHub Profile
def dayify(symbol,countsymbol,sumsymbol = nil)
# This is for calculating things like emails sent. Each time an update email is sent,
# one row is added to the Analytic table with the 'symbol'. Each analytic run, the past
# day of those symbols are rolled into one Analytic called 'countsymbol'. If there is a
# quantity specifed as 'newsymbol' then the values are aggregated and saved as 'newsymbol'.
# In the case of update emails, the number of updates is the aggregate, the number of emails
# is the count.
# Sample call for update emails: dayify(:update_email_sent,:daily_update_emails,:updates_in_daily_emails)
# Sample call for invite emails: dayify(:invite_email_sent,:daily_invite_emails)
z = Analytic.find_by_sql("select sum(value) as sum, count(value) as count, date_trunc('day',created_at) as x from analytics WHERE resource = '#{symbol.to_s}' AND created_at < date_trunc('day',now()) group by date_trunc('day',created_at)")
ActiveRecord::MultiparameterAssignmentErrors (1 error(s) on assignment of multiparameter attributes):
/vendor/rails/activerecord/lib/active_record/base.rb:2095:in `execute_callstack_for_multiparameter_attributes'
/vendor/rails/activerecord/lib/active_record/base.rb:2075:in `assign_multiparameter_attributes'
/vendor/rails/activerecord/lib/active_record/base.rb:1676:in `attributes='
/vendor/rails/activerecord/lib/active_record/base.rb:1592:in `update_attributes'
/usr/local/apache2/htdocs/gf_test/current/app/controllers/listing_controller.rb:472:in `update'
/usr/local/apache2/htdocs/gf_test/current/app/controllers/listing_controller.rb:446:in `update'
@kwilcox
kwilcox / gist:4164765
Created November 28, 2012 21:39
Satellite FMRC
<!-- FMRC Aggregation -->
<featureCollection featureType="FMRC" name="LakeErieSST-FMRC" harvest="true" path="LakeErieSST-FMRC">
<metadata inherited="true">
<serviceName>agg</serviceName>
<documentation type="summary">Lake Erie SST</documentation>
</metadata>
<collection spec="/var/thredds/MTRI-LST/erie_current_year/converted/.*nc4$"/>
<!-- The protoDataset changes are not reflected in the 'Best Time Series' -->
<protoDataset choice="Penultimate">
<netcdf xmlns="http://www.unidata.ucar.edu/namespaces/netcdf/ncml-2.2">
<?xml version="1.0" encoding="UTF-8"?>
<om:ObservationCollection xmlns:gml="http://www.opengis.net/gml" xmlns:om="http://www.opengis.net/om/1.0" xmlns:swe="http://www.opengis.net/swe/1.0.1" xmlns:swe2="http://www.opengis.net/swe/2.0" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" gml:id="SPOT5_DATA" xsi:schemaLocation="http://www.opengis.net/om/1.0 http://schemas.opengis.net/om/1.0.0/observation.xsd">
<om:member>
<om:Observation>
<om:samplingTime>
<gml:TimePeriod>
<gml:beginPosition>1990-01-01T00:00:00Z</gml:beginPosition>
<gml:endPosition>1990-01-01T00:00:00Z</gml:endPosition>
</gml:TimePeriod>
</om:samplingTime>
@kwilcox
kwilcox / gist:6514735
Created September 10, 2013 19:58
Installing Antlr/zlib/hdf4/hdf5/netcdf4/nco from source
#!/bin/bash
yum install -y gcc gcc-c++ gcc-gfortran curl-devel libxml2-devel bison flex wget make libjpeg-devel expat-devel gsl-devel
INSTALL_PATH=/opt
mkdir -p $INSTALL_PATH/src
# ANTLR2
APP=antlr-2.7.7
ANTLR_PATH=$INSTALL_PATH/$APP
@kwilcox
kwilcox / gist:7760238
Created December 2, 2013 22:28
Avoid numpy/netcdf4-python memory errors on flat arrays
def set_data_array(nc, variable, data):
# What is 50% of the available memory
available_memory = psutil.virtual_memory().available * .50
if data.nbytes > available_memory:
# Houston...
# Try 10 sub arrays. Should have some logic here to determine
# a better number of arrays to split this into
smallers = np.array_slice(data, 10)
i = 0 # track start index
@kwilcox
kwilcox / flask_admin.py
Last active June 20, 2019 13:42
WTForms and GeoAlchemy2
from flask.ext.admin.contrib.sqla import ModelView
# 'location' is the GeoAlchemy2 column
class FeatureView(ModelView):
...
form_overrides = dict(location=WTFormsMapField)
form_args = dict(
location=dict(
geometry_type='Polygon', height=500, width=500, cloudmade_api="{your_api}"
)
@kwilcox
kwilcox / ooi-startup.sh
Last active August 29, 2015 13:57
OOI startup
#!/bin/sh
. ~/source_ooi
. $HOME/.venvburrito/startup.sh
pushd .
COI_VIRTUALENV=ooi
UI_VIRTUALENV=ion-ux
@kwilcox
kwilcox / iso_harvest.py
Created May 27, 2014 13:42
Below is a python script that can be used to harvest THEDDS catalogs and save the ISO metadata files to a local directory Below is a python script that can be used to harvest THEDDS catalogs and save the ISO metadata files to a local directory
import os
import urllib
from thredds_crawler.crawl import Crawl
import logging
import logging.handlers
logger = logging.getLogger('thredds_crawler')
fh = logging.handlers.RotatingFileHandler('/var/log/iso_harvest/iso_harvest.log', maxBytes=1024*1024*10, backupCount=5)
fh.setLevel(logging.DEBUG)
ch = logging.StreamHandler()
@kwilcox
kwilcox / gist:6e7d7d74fdffaf7d21b5
Last active August 29, 2015 14:09
FreeIPA Replication
[root@auth ~]# ipa-replica-manage list
auth.axiom: master
auth.axiompvd: master
[root@auth ~]# ipa-replica-manage list -v `hostname`
auth.axiom: replica
last init status: None
last init ended: None
last update status: 0 Replica acquired successfully: Incremental update started
last update ended: None