Skip to content

Instantly share code, notes, and snippets.

@dannyduc
dannyduc / jq.sh
Created September 21, 2013 04:13
jq map array usage
curl -H Authorization:55560A2D-14F3-8706-96FE-7B6C6AAB2820\
'https://developer.ingenuity.com/datastream/api/v1/admin/accounts'\
jq '.[] | {userName, applicationName}'
@dannyduc
dannyduc / JsonPath.java
Last active December 23, 2015 14:09
Sample JsonPath code
import com.jayway.jsonpath.JsonPath;
public class Main {
public static final String JSON = "{\"links\":[{\"href\":\"http://localhost:8123/datastream/api/v1/activations/07cba26b-3916-43ba-9ac5-b07b7504d23a-126\",\"rel\":\"self\",\"method\":\"GET\"},{\"href\":\"http://localhost:8123/datastream/api/v1/activations/07cba26b-3916-43ba-9ac5-b07b7504d23a-126\",\"rel\":\"update\",\"method\":\"POST\"},{\"href\":\"http://localhost:8123/datastream/api/v1/activations/07cba26b-3916-43ba-9ac5-b07b7504d23a-126/validate\",\"rel\":\"validate\",\"method\":\"GET\"},{\"href\":\"http://localhost:8123/datastream/api/v1/activations/07cba26b-3916-43ba-9ac5-b07b7504d23a-126/execute\",\"rel\":\"execute\",\"method\":\"POST\"}],\"activation\":{\"id\":\"07cba26b-3916-43ba-9ac5-b07b7504d23a-126\",\"userName\":null,\"state\":\"VALIDATED\",\"creationDate\":null,\"lastModified\":{\"year\":2013,\"era\":1,\"dayOfYear\":263,\"dayOfWeek\":5,\"dayOfMonth\":20,\"centuryOfEra\":20,\"yearOfEra\":2013,\"yearOfCentury\":13,\"weekyear\":2013,\"mon
@dannyduc
dannyduc / svn.sh
Last active December 21, 2015 12:08
svn check out with no child folders
svn checkout --non-recursive http://svn.ingenuity.com:8081/repos/trunk/ing
cd ing
svn update ims_component
@dannyduc
dannyduc / casProxy.txt
Last active December 21, 2015 05:19
Notes on JASIG CAS proxy granting ticket protocol
CasProcessingFilterEntryPoint
redirect to cas for authentication with service url callback on success.
https://service.com/service/j_spring_cas_security_check
Cas20ServiceTicketValidator
listen for request to /j_spring_cas_security_check
1 read parameter ticket=serviceTicket
2 post validate ticket to cas along with pgt call back url (/j_spring_cas_security_proxyreceptor)
5 read pgtIou from response and load pgt from ProxyGrantingTicketStorage
6 saves pgt and ProxyRetriever to principal session wrapped in CasAuthenticationToken
@dannyduc
dannyduc / UserContextTest.java
Created August 16, 2013 21:35
Sample code to set user context
User imsUser = new User();
imsUser.setUserId(1);
imsUser.setUsername("[email protected]");
String password = "1234";
imsUser.setPassword(password);
License license = new License();
GrantedAuthority[] authorities = new GrantedAuthority[]{
new GrantedAuthorityImpl("ROLE_ME")
};
@dannyduc
dannyduc / pom.xml
Created August 16, 2013 14:02
Maven build single jar mvn assembly:single
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>client.Main</mainClass>
</manifest>
</archive>
@dannyduc
dannyduc / JerseyClientExample.java
Created August 16, 2013 14:00
Sample Jersey Client code to post JSON data
String uri = "https://developer.ingenuity.com/datastream/api/v1/activations/a9ab2c34-01b5-4473-864d-0d2f008ae090-5";
String input = "[{\"sampleId\":\"33\",\"activationCode\":\"Lab-act-code-xxx-zzz\"}]";
Client client = Client.create();
ClientResponse response = client.resource(uri)
.type(MediaType.APPLICATION_JSON)
.header("Authorization", "xxx")
.post(ClientResponse.class, input);
@dannyduc
dannyduc / CommandLineTokenizer.java
Last active December 21, 2015 04:09
Tokenize command line input with quoted characters
public class CommandLineTokenizer {
public static void main(String[] args) throws IOException, InterruptedException {
String cmdInput = "curl -X POST -H \"Content-Type:application/json\" -H \"Authorization: xxx\" -d '[{\"sampleId\":\"33\",\"activationCode\":\"Lab-act-code-xxx-zzz\"}]' https://developer.ingenuity.com/datastream/api/v1/activations/a9ab2c34-01b5-4473-864d-0d2f008ae090-5";
// tokenize with quote and single quote characters removed
List<String> matchTokens = new ArrayList<String>();
Pattern regex = Pattern.compile("[^\\s\"']+|\"([^\"]*)\"|'([^']*)'");
Matcher regexMatcher = regex.matcher(cmdInput);
while (regexMatcher.find()) {
@dannyduc
dannyduc / gist:3845549
Created October 6, 2012 17:34
postgresql commands
Location:
/Applications/Postgres.app/Contents/MacOS/bin/psql
JDBC Properties:
database.driverClassName=org.postgresql.Driver
database.url=jdbc\:postgresql\://localhost\:5432/salesquote
database.username=
database.password=
@dannyduc
dannyduc / gist:3845387
Created October 6, 2012 16:31
Remove files from git history
Rewrite history
git filter-branch -f --index-filter 'git rm -rf --cached --ignore-unmatch target/* .idea/*' --prune-empty -- --all
Cleanup and reclaim space
rm -rf .git/refs/original/
git reflog expire --expire=now --all
git gc --aggressive --prune=now