Skip to content

Instantly share code, notes, and snippets.

require(DT)
require(shiny)
custom.CSS <- "
.dataTables_scrollBody thead{
visibility:hidden;
}
.group{
@i-like-bikes
i-like-bikes / R_sux.R
Last active September 26, 2017 04:58
searchCols = vector('list', ncol(mtcars))
q = list('gear'=3, 'mpg'=10)
colNames = names(mtcars)
for(col_ in names(q)) {
pos = which(colNames == col_)
searchCols[[pos]] <- list(search = q[[col_]])
}
searchCols
q)rng: {[w;s;e] s + w*til ceiling(e-s)%w}
q)dt: rng[1;2000.01.01;2001.01.01] / generates list of dates for the year
q)data: {til x}'[(count dt)?1000] / generate some random data, sampling from 1000 - so avg should be about 500 a day.
q)tab: ungroup ([]date:{(count x)#y}'[data;dt];observation:data) / this is shit - but yknow, 6 months since paid for this shit
q)select avg dayCount by date.month from select dayCount: count i by date from tab / Damn son, that daily agg, turned into monthly avg.
month | dayCount
-------| --------
2000.01| 472.871
2000.02| 507.2759
2000.03| 477.6452
@i-like-bikes
i-like-bikes / temp.py
Last active January 20, 2018 09:21
temp.py
def do_math(x):
print(x ** 2)
return
if __name__ == '__main__':
i = input('Please insert an int: ')
assert int(i), 'Not an int. terminating'
i = int(i)
result = do_math(i)
def wat(x):
return x or 'WAT!!'
@i-like-bikes
i-like-bikes / lga_year.py
Created April 26, 2018 14:46
LGA and year filtering
import datetime
import logging
import sys
from mongoengine import connect
from mongoengine import DateTimeField, Document, EmbeddedDocument, EmbeddedDocumentField, IntField, ListField, StringField
from pymongo.errors import OperationFailure
# Solution comes from following this:
# https://stackoverflow.com/questions/28982285/mongodb-projection-of-nested-arrays
torrent: /home/rob/go/src/github.com/anacrolix/go-libutp/utp_internal.cpp:3314: int utp_getpeername(utp_socket*, sockaddr*, socklen_t*): Assertion `conn' failed.
SIGABRT: abort
PC=0x7fe6bcedb428 m=9
signal arrived during cgo execution
goroutine 9961 [syscall, locked to thread]:
runtime.cgocall(0x81c820, 0xc420519a10, 0x0)
/usr/local/go/src/runtime/cgocall.go:131 +0x110 fp=0xc4205199e0 sp=0xc4205199a0
github.com/anacrolix/go-libutp._Cfunc_utp_getpeername(0x0, 0xc4222e39d0, 0xc421cbc408, 0x0)
??:0 +0x4d fp=0xc420519a10 sp=0xc4205199e0
# https://stackoverflow.com/questions/11810461/how-to-perform-periodic-task-with-flask-in-python
from apscheduler.schedulers.background import BackgroundScheduler
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
# initialise Flask app
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:////tmp/test.db'
db = SQLAlchemy(app)