Skip to content

Instantly share code, notes, and snippets.

@brianv0
brianv0 / client_id.py
Created January 22, 2016 21:25
Random Client ID
import uuid
import struct
import base64
u = uuid.uuid4()
max_int64 = 0xFFFFFFFFFFFFFFFF
packed = struct.pack('>QQ', (u.int >> 64) & max_int64, u.int & max_int64)
client_id = base64.b64encode(packed)
print client_id
@brianv0
brianv0 / ghbackup.py
Created February 3, 2016 21:04
Organization Snapshots
import datetime
import sqlite3
from subprocess import Popen, PIPE
import Github
import sys
g = Github(sys.stdin[1])
def get_repo_list(organization):
gh_org = g.get_organization(organization)
@brianv0
brianv0 / VOTableTest.java
Last active March 16, 2016 21:36
Example VOTable simple protobuf
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package org.lsst.ivoa.votable;
import com.google.protobuf.InvalidProtocolBufferException;
import java.io.UnsupportedEncodingException;
import org.junit.Test;
@brianv0
brianv0 / logscrape.py
Last active March 12, 2016 00:34
Pipeline-II logscraper with CSV output
import sys
import subprocess
import os
import re
"""
Pipeline-II Logscraper
You must run this at SLAC currently.
@brianv0
brianv0 / actual_query.json
Last active March 17, 2016 00:40
Example JSON output
{
"result": {
"table": {
"data": [
[
8404051561545729,
125230127
],
[
8404051561545730,
@brianv0
brianv0 / dump.sh
Last active March 18, 2016 23:28
pysqlite with sqlite3_column_type
Python 2.7.10 (v2.7.10:15c95b7d81dc, May 23 2015, 09:33:12)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from pysqlite2 import dbapi2 as sqlite3
>>>
>>>
>>> conn = sqlite3.connect()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: Required argument 'database' (pos 1) not found
@brianv0
brianv0 / builder.j2
Last active March 22, 2016 20:41
Simple IDL loosely based on capnproto
{%- macro safe_type(type) -%}
{%- if type in java_mappings -%}
{{ java_mappings[type] }}
{%- else -%}
{{ type }}
{%- endif -%}
{%- endmacro -%}
class {{ name }} {
@brianv0
brianv0 / sql.g4
Last active March 28, 2016 22:15
antlr4
!/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@brianv0
brianv0 / adql.sql
Created March 30, 2016 23:59
adql example
SELECT *
FROM "II/295/SSTGC","II/293/glimpse"
WHERE 1=CONTAINS(
POINT('ICRS',"II/295/SSTGC".RAJ2000,"II/295/SSTGC".DEJ2000),
BOX('GALACTIC', 0, 0, 30/60., 10/60.)
)
AND 1=CONTAINS(
POINT('ICRS',"II/295/SSTGC".RAJ2000,"II/295/SSTGC".DEJ2000),
CIRCLE('ICRS',"II/293/glimpse".RAJ2000,"II/293/glimpse".DEJ2000, 2/3600.)
)
@brianv0
brianv0 / presto-output.txt
Last active April 5, 2016 22:37
Query Parse
Query{queryBody=QuerySpecification{select=Select{distinct=false, selectItems=[(CASE WHEN ("x" = 1) THEN "y" ELSE "z" END), "a"]}, from=Optional[Join{type=IMPLICIT, left=Table{ii/295/sstgc}, right=Table{ii/293/glimpse}, criteria=Optional.empty}], where=((1 = "contains"("point"('ICRS', "ii/295/sstgc"."raj2000", "ii/295/sstgc"."dej2000"), "box"('GALACTIC', 0, 0, (30 / 60.0), (10 / 60.0)))) AND (1 = "contains"("point"('ICRS', "ii/295/sstgc"."raj2000", "ii/295/sstgc"."dej2000"), "circle"('ICRS', "ii/293/glimpse"."raj2000", "ii/293/glimpse"."dej2000", (2 / 3600.0))))), groupBy=[], having=null, orderBy=[], limit=10}, orderBy=[]}
SELECT
(CASE WHEN ("x" = 1) THEN "y" ELSE "z" END)
, "a"
FROM
ii/295/sstgc
, ii/293/glimpse
WHERE ((1 = "contains"("point"('ICRS', "ii/295/sstgc"."raj2000", "ii/295/sstgc"."dej2000"), "box"('GALACTIC', 0, 0, (30 / 60.0), (10 / 60.0)))) AND (1 = "contains"("point"('ICRS', "ii/295/sstgc"."raj2000", "ii/295/sstgc"."dej2000"), "circle"('ICRS', "ii/293/glimpse"."raj2000", "ii/293/glimpse"."d