Skip to content

Instantly share code, notes, and snippets.

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 / lmgen.sh
Last active March 15, 2018 16:21
Language Model Generator - Supply corpus text file and it will use cmu's online generator to generate and download the dictionary, language model and binary language model
#!/bin/bash
# Copyright (c) 2014-Present, Scott Cagno
# All rights reserved. [BSD License]
# ------------------------------------------
# THIS BASH SCRIPT UPLOADS A CORPUS FILE TO
# THE CMU ONLINE LANGUAGE MODELING GENERATOR.
# IT WILL RETURN AND STAGE THE GENERATED
# LANGUAGE MODEL AND DICTIONARY FILES IN THE
# SPECIFIED DIRECTORY (LANGDIR).
@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;
@scottcagno
scottcagno / table.js
Created March 10, 2015 15:25
Basic table type data structure in javascript
var table = {
colNames: [],
rowNames: [],
cells: {},
addRow: function(rowName) {
add = true;
for(var i = 0; i < this.rowNames.length; i++) {
if(rowName[i] === rowName) add = false;