Skip to content

Instantly share code, notes, and snippets.

View titanjer's full-sized avatar
🏠

Titan Lin titanjer

🏠
  • Taiwan
View GitHub Profile
@titanjer
titanjer / modules.jq
Created December 22, 2023 08:26
Dynamodb Marshall by JQ
def marshall:
def m:
def to_string: {S:.};
def to_number: {N:.|tostring};
def to_boolean: {BOOL:.};
def to_array: {L:.|to_entries|map(.value|m)};
def to_object: {M:.|map_values(m)};
def to_null: {NULL:true};
if .|type=="string" then .|to_string
elif .|type=="number" then .|to_number
@titanjer
titanjer / athena.ts
Created July 25, 2023 07:15
athena.ts
import {
AthenaClient,
GetQueryExecutionCommand,
QueryExecutionState,
StartQueryExecutionCommand
} from "@aws-sdk/client-athena";
const client = new AthenaClient({});
const runAthenaQuery = async (queryString: string, workGroup: string): Promise<any> => {
{ "dataCount":422 ,"xtype":"" , "Xcount" : {"event":58,"gov":56,"incubator":118,"edu":5,"funding":5,"corporate":2,"cowork":99,"publicS":7,"train":42,"society":28,"others":2},"total_events":58,"total_members":229,"data" : [{"y":"22.99995210","x":"120.21504670","L":"http:\/\/sme.moeasmea.gov.tw\/startup\/modules\/resource\/detail\/?sId=12","T":"C-Hub \u6210\u5927\u5275\u610f\u57fa\u5730","A":"\u81fa\u5357\u5e02\u6771\u5340\u5927\u5b78\u8def1\u865f","I":"edu"},{"y":"24.14467450","x":"120.66267870","L":"http:\/\/sme.moeasmea.gov.tw\/startup\/modules\/resource\/detail\/?sId=15","T":"CVS \u5171\u540c\u5de5\u4f5c\u7a7a\u9593","A":"\u81fa\u4e2d\u5e02\u897f\u5340\u6c11\u751f\u8def368\u5df72\u5f043\u865f","I":"cowork"},{"y":"22.61151800","x":"120.30031500","L":"http:\/\/sme.moeasmea.gov.tw\/startup\/modules\/resource\/detail\/?sId=18","T":"DesignV\u8de8\u57df\u5171\u540c\u5275\u610f\u7a7a\u9593","A":"\u9ad8\u96c4\u5e02\u82d3\u96c5\u5340\u81ea\u5f37\u4e09\u8def3\u865f35\u6a13-7( I )\u5ba4","I":"cowork"},{"y":"25.022136
@titanjer
titanjer / gist:211eb001e9a3cf6c0063
Last active December 16, 2015 07:06
fluentd s3 log
<source>
type tail
path /var/log/cflogs/s3/access.log
pos_file /var/log/cflogs/s3/access.log.pos
format /^(?<owner>[^ ]*) (?<bucket>[^ ]*) \[(?<time>.*)\] (?<remote_ip>[^ ]*) (?<requester>[^ ]*) (?<request_id>[^ ]*) (?<operation>[^ ]*) (?<key>[^ ]*) \"(?<request_uri>.*)\" (?<http_status>[^ ]*) (?<error_code>[^ ]*) (?<bytes_sent>[^ ]*) (?<object_size>[^ ]*) (?<time_total>[^ ]*) (?<turn_around_time>[^ ]*) \"(?<referrer>.*)\" \"(?<user_agent>.*)\" (?<version_id>[^ ]*)/
time_format %d/%b/%Y:%H:%M:%S %z
tag s3.es.uri_escape
</source>
from scrapy.contrib.spiders import CrawlSpider
from scraper.items import ProductItem
from scrapy import log
import re
import json
# curl http://192.168.1.100:6800/schedule.json -d project=scraper -d spider=importjl -d setting=STORE=24 -d setting=RQ_QUEUE=scraper
class ImportjlSpider(CrawlSpider):
@titanjer
titanjer / gist:c137e32cfcf8e5e0b41f
Created June 24, 2014 04:25
mongomock getCollection example
globalconnection = None
def get_mongodb_connect_url():
if IS_PRODUCTION:
return ('mongodb://fuck:yourmother'
'mongodb-1.fuck.com:27017,'
'mongodb-2.fuck.com:27017,'
'mongodb-3.fuck.com:27017,'
'mongodb-4.fuck.com:27017')
@titanjer
titanjer / md5-decrypt
Created June 21, 2014 20:01
geek.py Q1
import sys
import time
import string
import hashlib
import itertools
def main(filename, output):
with open(filename) as f:
#!/bin/bash
set -o errexit
set -o nounset
if [[ ${#} -ne 1 ]]
then
echo "Usage: ${0} upstart-conf-file" >&2
exit 1
fi
#!/usr/bin/env bash
# Pre-requisites
sudo apt-get -y update
sudo apt-get --no-install-recommends -y install build-essential openssl libreadline6 libreadline6-dev curl git-core zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt-dev autoconf libc6-dev libgdbm-dev ncurses-dev automake libtool bison subversion pkg-config libffi-dev vim
# Download and compile Ruby 2.0.0-p0
cd /tmp
wget ftp://ftp.ruby-lang.org/pub/ruby/2.0/ruby-2.0.0-p0.tar.gz
tar -xvzf ruby-2.0.0-p0.tar.gz
def html_decorator(func):
"""
This decorator wraps the output in html.
(From http://stackoverflow.com/a/14647943)
"""
def _decorated(*args, **kwargs):
response = func(*args, **kwargs)
wrapped = ("<html><body>",