Skip to content

Instantly share code, notes, and snippets.

View goodpic's full-sized avatar

Jun Kaneko goodpic

View GitHub Profile
$(document).ready(function(){
// Configure jQuery oEmbed library
$.fn.oembed.defaults = {
maxWidth: 500, maxHeight: 400,
embedMethod: "append" // "replace", "auto", "append", "fill"
};
// Append the oEmbed contents fetched from #oembed_url
$("form#oembed_form").submit( function () {
// ==UserScript==
// @name MT Disable Spam Users
// @description Display URL and email address and check keywords to delete spam users.
// @include http://YOUR-MT-DOMAIN/cgi-bin/mt/mt.cgi*
// ==/UserScript==
var $;
// Add jQuery
(function(){
if (typeof unsafeWindow.jQuery == 'undefined') {
module Types
class QueryType < GraphQL::Schema::Object
# Add root-level fields here.
# They will be entry points for queries on your schema.
# queries are represented as fields, use [Types::XXX] for the list
field :product, Types::ProductType,
null: true,
resolve: ->(_obj, args, _ctx) {
Product.find(args.id)
module Types
# Product schema
class ProductType < GraphQL::Schema::Object
# Name of this Type
graphql_name 'Product'
field :sales_history, [Types::SalesHistoryType],
null: true,
resolve: ->(product, args, ctx) {
days = ctx.irep_node.parent.arguments.days || 7
+-------------------+-----------+----------+-----------------------------------------+
| Field name | Type | Mode | Description |
+-------------------+-----------+----------+-----------------------------------------+
| id | INTEGER | REQUIRED | |
| shop_name | STRING | NULLABLE | |
| transaction_id | INTEGER | NULLABLE | Transaction which this item belongs |
| product_id | INTEGER | NULLABLE | Unique internal product ID |
| barcode | STRING | NULLABLE | Universal product ID |
| category_code | STRING | NULLABLE | ID of the category |
| category_name | STRING | NULLABLE | Name of the category |
@goodpic
goodpic / gist:d3e168a58dcfd4c984df7ab0052ac2f2
Last active September 10, 2018 23:55
Sample table: Shop transaction
+-------------------+-----------+----------+-------------------------+
| Field name | Type | Mode | Description |
+-------------------+-----------+----------+-------------------------+
| id | INTEGER | REQUIRED | Transaction ID |
| shop_name | STRING | NULLABLE | |
| customers | INTEGER | NULLABLE | Number of customers |
| sales | NUMERIC | NULLABLE | Total sales |
| tax | NUMERIC | NULLABLE | VAT tax paid |
| cost | NUMERIC | NULLABLE | Total costs |
| discount | NUMERIC | NULLABLE | Total discount |
@goodpic
goodpic / hourly_sales.sql
Last active September 11, 2018 00:21
Hourly sales
SELECT
TIMESTAMP_TRUNC(invoiced_at, HOUR) AS timestamp
, DATETIME_TRUNC(local_invoiced_at, HOUR) AS date_hour
, FORMAT_DATETIME("%A", local_invoiced_at) AS day
, MOD(CAST(FORMAT_DATETIME("%u", local_invoiced_at) AS int64), 7) AS day_num
, FORMAT_DATETIME("%H", local_invoiced_at) AS hour
, shop_name
, COUNT(*) AS transactions
, SUM(customers) AS customers
, SUM(sales) AS sales
@goodpic
goodpic / bigquery-create-a-new-table.js
Last active September 15, 2018 21:47
BigQuery Create a new table
const BigQuery = require('@google-cloud/bigquery');
const bigquery = new BigQuery({ YOUR_PROJECT_ID });
const handleError = (err) => {
if (err && err.name === 'PartialFailureError') {
if (err.errors && err.errors.length > 0) {
console.log('Insert errors:');
err.errors.forEach(error => console.error(error));
}
} else {
@goodpic
goodpic / SchemaSalesByHour.js
Created September 15, 2018 21:54
Create BigQuery table
exports.SchemaSalesByHour = [
{
description: 'Date and hour of the transactions',
name: 'date_hour',
type: 'DATETIME',
mode: 'REQUIRED'
},
{
description: 'UTC timestamp of the transactions',
name: 'timestamp',
@goodpic
goodpic / create.js
Created September 15, 2018 22:02
Commander.js command line to create a new BigQuery table
const program = require('commander');
const { createTable } = require('../src/bigquery');
const { SchemaSalesByHour } = require('../schemas/SchemaSalesByHour');
program
.version('0.1.0')
.option('-t, --table [table]', 'Specify the table to create', '')
.parse(process.argv);