Skip to content

Instantly share code, notes, and snippets.

@scottcagno
scottcagno / crawl.sh
Last active August 29, 2015 13:57
simple curl wrapper to aid in web testing
#!/bin/bash
# File: crawl.sh
# Desc: Package designed to provide an API to help automate web testing
# Dependencies: curl, getopts
# Copyright 2014, Scott Cagno, All rights reserved.
# usage function
function usage() {
echo -e "usage: $0 <opts> -h [host-uri]"
echo -e " opts:"
@scottcagno
scottcagno / install_spring.sh
Created March 12, 2014 17:54
spring source installer
#!/bin/bash
sudo echo "Need to be root, please authenticate..."
echo "Downloading spring source..."
curl -o sts.tar.gz http://download.springsource.com/release/STS/3.4.0/dist/e4.3/spring-tool-suite-3.4.0.RELEASE-e4.3.1-linux-gtk-x86_64.tar.gz
echo "Extracting..."
tar -xf sts*.tar.gz
echo "Staging..."
sudo mv springsource /opt
echo "Creating symbolic links..."
sudo ln -s /opt/springsource/sts*/STS /usr/local/bin/sts
public class CodeModelIfForExample {
private static final String CLASS_NAME = "TestClass";
public static void main(String args[]) throws Exception{
JCodeModel codeModel = new JCodeModel();
JDefinedClass c = codeModel._class(CLASS_NAME);
writeIfElse(codeModel, c);
@scottcagno
scottcagno / ResourceRestController.java
Created June 2, 2014 14:15
Example REST style controller
@Controller
public class ResourceRestController {
@RequestMapping(value="/resource/item", method=RequestMethod.GET)
@ResponseBody
public String list() {
return "list items hit";
}
@RequestMapping(value="/resource/item", method=RequestMethod.POST)
@scottcagno
scottcagno / spring_security_password_encode_example.txt
Created June 5, 2014 17:45
Spring Security - Password Encode Example
In SecurityConfig.java (config)
======================
...
auth.jdbcAuthentication()
.dataSource(...)
.passwordEncoder(passEncoder()) <--- ADD
.usersByUsernameQuery(...)
.authoritiesByUsernameQuery(...);
...
@scottcagno
scottcagno / install_java8
Created June 17, 2014 14:11
install and stage java8 using apt-get
#!/bin/bash
# install and stage java8 using apt-get
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get -y install oracle-java8-installer
sudo apt-get autoremove
sudo apt-get -y install oracle-java8-set-default
@scottcagno
scottcagno / object to map
Created July 11, 2014 15:47
Java Object To Map via introspection
public static Map<String, Object> introspect(Object obj) throws Exception {
Map<String, Object> result = new HashMap<String, Object>();
BeanInfo info = Introspector.getBeanInfo(obj.getClass());
for (PropertyDescriptor pd : info.getPropertyDescriptors()) {
Method reader = pd.getReadMethod();
if (reader != null)
result.put(pd.getName(), reader.invoke(obj));
}
return result;
}
@scottcagno
scottcagno / supervisord.conf
Last active August 29, 2015 14:08
supervisord template config file
[program:NAME]
command=java -Xms128m -Xmx1g -XX:+UseCompressedOops -XX:+UseParNewGC -XX:+UseConcMarkSweepGC -jar /opt/NAME.jar
autostart=true
autorestart=true
stderr_logfile=/var/log/NAME.err.log
stdout_logfile=/var/log/NAME.out.log
...
NOTES:
@scottcagno
scottcagno / web_regex
Created November 21, 2014 18:26
regex to catch html or javascript in most cases.
(<(?:"[^"]*"['"]*|'[^']*'['"]*|[^'">])+>)|((function)|\(|\)|\;|([a-z]\.[a-z])|\{|\})
a,
a:focus,
a:hover {
color: #fff
}
.btn-default,
.btn-default:focus,
.btn-default:hover {
color: #333;