Skip to content

Instantly share code, notes, and snippets.

View tmclnk's full-sized avatar

Tom McLaughlin tmclnk

View GitHub Profile
@tmclnk
tmclnk / login.html
Last active August 29, 2015 14:02 — forked from entaq/Google_oAuth.js
OAuth2 end-to-end example for client auth using newStateToken
FAQ
Why open a new window for the authorization?
Because if you load the contents of the auth page directly IN a sidebar (or script) using HtmlService, its buttons won't work because they've been cajoled.
Why not just the the access token provided by GAS Libraries?
Because lord only knows what that thing is scoped for.
How do I clear my token?
Pass ?reset parameter to the url, or call clearMyAuthToken() directly.
@tmclnk
tmclnk / GPARSDynamicDispatchDSL
Created May 26, 2015 12:51
GPARS Dynamic Dispatch DSL
import groovyx.gpars.actor.*
import org.codehaus.groovy.runtime.NullObject
import groovy.time.TimeCategory
DynamicDispatchActor actor = Actors.messageHandler {
when { String name ->
println "Nice to meet you $name"
}
when { Integer age ->
println "You look younger than $age"
@tmclnk
tmclnk / GPARS Dynamic Dispatch
Last active August 29, 2015 14:21
GPARS Dynamic Dispatch
import groovyx.gpars.actor.DynamicDispatchActor
import org.codehaus.groovy.runtime.NullObject
import groovy.time.TimeCategory
def actor = new DynamicDispatchActor(){
private int counter = 0
void onMessage(String message) {
counter += message.size()
println "Actor received string $message"
}
@tmclnk
tmclnk / GPARS Actor DSL
Created May 26, 2015 12:53
GPARS Actor DSL
import groovyx.gpars.actor.*
import org.codehaus.groovy.runtime.NullObject
import groovy.time.TimeCategory
// use the DSL to create our actor instead of
def actor = Actors.actor {
loop {
// NOTE the actor's message handler can only take 0 or 1 args
react { String word ->
println "Actor received $word"
@tmclnk
tmclnk / GPARS Data Flow
Created May 26, 2015 13:20
GPARS Data Flow
import static groovyx.gpars.dataflow.Dataflow.*
import groovyx.gpars.dataflow.*
// The Dataflow Variables have a pretty straightforward semantics.
// When a task needs to read a value from DataflowVariable
// (through the val property), it will block until the value has been
// set by another task or thread (using the '<<' operator).
// Each DataflowVariable can be set only once in its lifetime.
// Notice that you don't have to bother with ordering and synchronizing
@tmclnk
tmclnk / GPars Dataflow Queue with Cancel
Created May 26, 2015 13:55
GPars Dataflow Queue with Cancel
import static groovyx.gpars.dataflow.Dataflow.task
import groovyx.gpars.dataflow.DataflowQueue
import java.util.concurrent.atomic.AtomicBoolean
final def buffer = new DataflowQueue()
final done = new AtomicBoolean()
def t = task {
while(!done.get()) {
def word = System.console().readLine 'Enter some text (or "stop" to stop): '
@tmclnk
tmclnk / setproxy.bat
Last active August 29, 2015 14:22
Windows Batch File to set Proxy Server in Grails 2.x
@echo off
REM USE THIS FILE IF YOU HAVE GRAILS CONFIGURED
set "psCommand=powershell -Command "$pword = read-host 'Enter Password' -AsSecureString ; ^
$BSTR=[System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($pword); ^
[System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR)""
for /f "usebackq delims=" %%p in (`%psCommand%`) do set password=%%p
grails add-proxy myproxy "--host=proxy_server" "--port=8020" "--username=%USERNAME%" "--password=%password%"
grails use-proxy myproxy
package be.shouldyou;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
@tmclnk
tmclnk / XML.java
Last active December 18, 2017 22:10
XML Wrapper in Java to reduce boilerplate XPath, DocumentBuilder, and Transformer work
package be.shouldyou;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
@tmclnk
tmclnk / HibernateClassBypassingLoadTimeWeaver.java
Last active January 18, 2018 17:30
Utility class using JDK's tools.jar to instrument a VM at runtime (e.g. for using hibernate proxies that lazily load @lob, but without compile-time instrumentation)
package gov.ne.revenue.mef.enhancement;
import java.lang.instrument.ClassFileTransformer;
import java.lang.instrument.IllegalClassFormatException;
import java.security.ProtectionDomain;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.instrument.classloading.LoadTimeWeaver;
import org.springframework.util.Assert;