Skip to content

Instantly share code, notes, and snippets.

@Coaden
Coaden / groupandtotal1.sql
Last active August 29, 2015 13:57
sql to group by date :: raw example
WITH dates_table AS (
SELECT created::date AS date_column FROM sharer_emailshare WHERE showroom_id=5
)
SELECT series_table.date, COUNT(dates_table.date_column), SUM(COUNT(dates_table.date_column)) OVER (ORDER BY series_table.date) FROM (
SELECT (last_date - b.offs) AS date
FROM (
SELECT GENERATE_SERIES(0, last_date - first_date, 1) AS offs, last_date from (
SELECT MAX(date_column) AS last_date, (MAX(date_column) - '1 year'::interval)::date AS first_date FROM dates_table
) AS a
) AS b
@Coaden
Coaden / groupandtotalbyday.py
Last active August 29, 2015 13:57
the more complicated grouping/totaling by date
sql = "WITH dates_table AS ( " \
" SELECT created_at::date AS date_column FROM text_textdb WHERE stream_id=%s " \
") " \
"SELECT series_table.date, COUNT(dates_table.date_column), SUM(COUNT(dates_table.date_column)) " \
"OVER (ORDER BY series_table.date) FROM ( " \
"SELECT (last_date - b.offs) AS date "\
"FROM ( " \
"SELECT GENERATE_SERIES(0, (last_date - first_date) -1, 1) AS offs, last_date from ( " \
"SELECT %s::date AS last_date, %s::date AS first_date " \
") AS a " \
@Coaden
Coaden / goup_by_date_with_totals.py
Created March 19, 2014 12:21
Simpler gouping by date,and easier for changing to hours and later adding the join to the classification DB
sql = "SELECT t.date, COUNT(se.id) FROM (" \
" SELECT to_char(date_trunc('day', (%s::TIMESTAMP - offs )), 'YYYY-MM-DD')" \
" AS date" \
" FROM GENERATE_SERIES(0, %s, 1)" \
" AS offs" \
") t " \
"LEFT OUTER JOIN (" \
" SELECT id, created_at::TIMESTAMP FROM text_textdb" \
" WHERE stream_id=%s" \
") se " \
@Coaden
Coaden / gist:e230be2f1c62161b89d1
Created January 14, 2015 21:40
Swiping code for Android
View myView = findViewById(R.layout.calender_main);
myView.setOnTouchListener(new OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction())
{
case MotionEvent.ACTION_DOWN:
{
oldTouchValue = event.getX();
break;
}
@Coaden
Coaden / Module Pattern example
Last active March 9, 2016 14:04
Sample Module Patterns for Javascript jQuery
var myNamespace = (function () {
var myPrivateVar, myPrivateMethod;
// A private counter variable
myPrivateVar = 0;
// A private function which logs any arguments
myPrivateMethod = function( foo ) {
console.log( foo );
@Coaden
Coaden / Module Pattern Example (Prototype)
Last active March 9, 2016 14:05
JavaScript Module Pattern Example with Prototype
if (!CalendarForm) {
// constructor
CalendarForm = function () {
var self = this;
var clientID = @hml....
$('#addAppointmentButton').on('click', function() {
@Coaden
Coaden / gulp.js
Last active February 24, 2016 15:07
Gulp.js File for VS / ng2 / typescipt + packages.json + tsconfig.json
var gulp = require('gulp');
var rimraf = require('rimraf');
var clean = require('gulp-clean');
var ts = require('gulp-typescript');
var merge = require('merge-stream');
var sourcemaps = require('gulp-sourcemaps');
var tslint = require('gulp-tslint');
var paths = {
webroot: './wwwroot',
@Coaden
Coaden / gulp.js
Last active March 4, 2016 15:27
gulp.js file for compiling typescript and map, removing and copying libs, etc for Visual Studio vNext All js and map in same location.
var gulp = require('gulp');
var rimraf = require('rimraf');
var clean = require('gulp-clean');
var ts = require('gulp-typescript');
var merge = require('merge-stream');
var sourcemaps = require('gulp-sourcemaps');
var tslint = require('gulp-tslint');
var watch = require('gulp-watch');
var paths = {
@Coaden
Coaden / dbContext.SaveChanges
Created March 9, 2016 14:03
dbContext SaveChanges() with Trace Output
try
{
dbModel.SaveChanges();
}
catch (DbEntityValidationException dbEx)
{
foreach (var validationErrors in dbEx.EntityValidationErrors)
{
foreach (var validationError in validationErrors.ValidationErrors)
{
//Go to chrome://settings-frame/passwords and F12, then paste this into Console and hit enter.
var decryptedRow="";
var pm = PasswordManager.getInstance();
var model = pm.savedPasswordsList_.dataModel;
var pl = pm.savedPasswordsList_;
for(i=0;i<model.length;i++){
PasswordManager.requestShowPassword(i);
};
setTimeout(function(){
decryptedRow += '"Name","URL","Username","Password"';