Skip to content

Instantly share code, notes, and snippets.

@brizandrew
brizandrew / server.py
Last active December 19, 2023 10:16
Simple Flask Webhook Example
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from flask import Flask, request
from urllib import unquote_plus
import json
import re
app = Flask(__name__)
// import_json_appsscript.js
// https://gist.github.com/allenyllee/c764c86ed722417948fc256b7a5077c4
//
// Changelog:
// (Oct. 16 2019) tag: allenyllee-20191016
// 1. Fixed google script error: urlfetchapp - service invoked too many times https://stackoverflow.com/questions/10598179/google-apps-script-urlfetchapp-service-invoked-too-many-times
// (Jul. 16 2018) tag: allenyllee-20180716
// 1. Fixed the issue "If you try to query /arrayA[k]/arrayB[n]/arrayC[m]/.../member, you will always get /arrayA[k]/arrayB[k]/arrayC[k]/.../member."
// (Nov. 30 2017) tag: allenyllee-20171130
// 1. Add the ability to query array elements by using xpath like "/array[n]/member" where "n" is array index
var active = false;
function changeRefer(details) {
if (!active) return;
for (var i = 0; i < details.requestHeaders.length; ++i) {
if (details.requestHeaders[i].name === 'Referer') {
details.requestHeaders[i].value = 'http://www.google.com/';
break;
}
/**
* Retrieves all the rows in the active spreadsheet that contain data and logs the
* values for each row.
* For more information on using the Spreadsheet API, see
* https://developers.google.com/apps-script/service_spreadsheet
*/
function readRows() {
var sheet = SpreadsheetApp.getActiveSheet();
var rows = sheet.getDataRange();
var numRows = rows.getNumRows();
@vs4vijay
vs4vijay / GetDataFromXPath
Created September 27, 2013 06:35
Extract Data from XPath via Google Apps Script
function getDataFromXpath(path, url) {
var data = UrlFetchApp.fetch(url);
var text = data.getContentText();
var xmlDoc = Xml.parse(text, true);
// Replacing tbody tag because app script doesnt understand.
path = path.replace("/html/","").replace("/tbody","","g");
var tags = path.split("/");
Logger.log("tags : " + tags);
// getting the DOM of HTML
@johnjreiser
johnjreiser / DownloadExtractParcels.py
Last active January 24, 2022 18:46
Script to download the GIS parcel and MOD-IV tax assessor databases from NJGIN, the State of New Jersey's online data and metadata repository. Essex and Middlesex are currently in "draft" form and are available through a separate download on NJGIN.
import urllib, os, sys, zipfile
def download(url,name=""):
if(name == ""):
name = url.split('/')[-1]
webFile = urllib.urlopen(url)
localFile = open(name, 'w')
fname = localFile.name
localFile.write(webFile.read())
webFile.close()
@ndarville
ndarville / business-models.md
Last active January 13, 2024 17:27
Business models based on the compiled list at http://news.ycombinator.com/item?id=4924647. I find the link very hard to browse, so I made a simple version in Markdown instead.

Business Models

Advertising

Models Examples
Display ads Yahoo!
Search ads Google
@jhaus
jhaus / gdocs-audio-player-bookmarklet.js
Created January 4, 2012 22:13
Google Docs Audio Player. Prefix with "javascript:" when adding to bookmarks. Bookmarklet broken as of 2010.01.04.
function gup( name ){
var cre_getDocIdelement = document.getElementById( 'gbmpm_0_l' );
name = name.replace( /[\[]/,"\\\[" ).replace( /[\]]/,"\\\]" );
var regexS = "[\\?&]" + name + "=([^&#]*)";
var regex = new RegExp( regexS );
var results = regex.exec( cre_getDocIdelement );
if( results == null ) return "";
@jhaus
jhaus / .htaccess
Created November 22, 2011 09:16
Simple Apache rewrite for index.html to the root url. Source/discussion: http://www.webmasterworld.com/google/3105248.htm
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{THE_REQUEST} ^.*\/index\.html?
RewriteRule ^(.*)index\.html?$ http://example.com$1 [R=301,L]
# More resources:
#
# http://old.justinshattuck.com/2007/01/19/apache-mod_rewrite-cheat-sheet/
# http://net.tutsplus.com/tutorials/other/a-deeper-look-at-mod_rewrite-for-apache/
@yosemitebandit
yosemitebandit / readme
Created October 18, 2011 22:27
uppify web demo with flask
This little 'app' responds in uppercase with whatever url path you specify.
It's the Flask-based alternative of the Django example written up here: http://gun.io/blog/python-for-the-web/
to make it work, create this directory structure:
uppify/
| - serve.py
| - templates/
| - uppify.html