Skip to content

Instantly share code, notes, and snippets.

killall -9 mongod
killall -9 mongo
mkdir -p /usr/local/var/mongodb
mkdir -p /usr/local/var/mongodb-slave1
mkdir -p /usr/local/var/mongodb-slave2
mongod --port 27017 --master --dbpath /usr/local/var/mongodb --replSet rs0 --config mongodb.conf &
mongod --port 37017 --slave --dbpath /usr/local/var/mongodb-slave1 --replSet rs0 --config mongodb.conf &
mongod --port 47017 --dbpath /usr/local/var/mongodb-slave2 --replSet rs0 --config mongodb.conf &
@ck1125
ck1125 / walk.js
Created December 24, 2012 14:55
walk with exclusion filter
#!/usr/bin/env node
var walk = require('walk');
var files = [];
var excludeFolders = ['.git','test','scripts','logs','config'];
var excludeFiles = ['README.md','pack.js','testem.json','key.pem','.DS_Store','.gitignore']
// Walker options
var walker = walk.walk('.', { followLinks: false });
var matchExcludeFolders = function(root) {
@ck1125
ck1125 / override.groovy
Created August 21, 2012 01:23
override bean
@Bean
static PropertySourcesPlaceholderConfigurer properties() {
PropertySourcesPlaceholderConfigurer pspc = new PropertySourcesPlaceholderConfigurer()
ListPropertySources sources = new ListPropertySources([
new GroovyConfigPropertySource('file-override', new UrlResource('file:///data/Config.groovy')),
new GroovyConfigPropertySource('config', new ClassPathResource('config/Config.config'))
])
pspc.setPropertySources(sources)
@ck1125
ck1125 / ListPropertySources
Created August 21, 2012 01:23
Propertysources extension
package com.in3k8.javaconfig.config.propertysource
import org.springframework.core.env.PropertySources
import org.springframework.core.env.PropertySource
class ListPropertySources implements PropertySources {
@ck1125
ck1125 / GroovyConfigPropertySource.groovy
Created August 21, 2012 01:22
propertysource extension
package com.in3k8.javaconfig.config.propertysource
import org.springframework.core.env.PropertySource
import org.springframework.core.io.Resource
class GroovyConfigPropertySource extends PropertySource {
Resource resource
Map configObject = [:]
@ck1125
ck1125 / OptionalRequestBody
Created August 7, 2012 20:06
optional request body annotation
import java.lang.annotation.Documented
import java.lang.annotation.ElementType
import java.lang.annotation.Retention
import java.lang.annotation.RetentionPolicy
import java.lang.annotation.Target
@Target(ElementType.PARAMETER)
import org.springframework.core.MethodParameter
import org.springframework.http.converter.StringHttpMessageConverter
import org.springframework.mock.web.MockHttpServletRequest
import org.springframework.mock.web.MockHttpServletResponse
import org.springframework.web.context.request.ServletWebRequest
import org.springframework.web.method.support.ModelAndViewContainer
import spock.lang.Specification
@ck1125
ck1125 / OptionalRequestBodyMethodProcessor.groovy
Created August 7, 2012 20:05
optional request body method parameter processor
import org.springframework.core.MethodParameter
import org.springframework.http.HttpInputMessage
import org.springframework.http.converter.HttpMessageConverter
import org.springframework.web.bind.support.WebDataBinderFactory
import org.springframework.web.context.request.NativeWebRequest
import org.springframework.web.method.support.ModelAndViewContainer
import org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor
class OptionalRequestBodyMethodProcessor extends RequestResponseBodyMethodProcessor {
@ck1125
ck1125 / request-body-application-context.xml
Created August 7, 2012 20:04
optional request body in spring 3.1
<mvc:annotation-driven conversion-service="conversionService">
<mvc:argument-resolvers>
<bean class="OptionalRequestBodyMethodProcessor" >
<constructor-arg name="messageConverters" ref="customMessageConverters" />
</bean>
</mvc:argument-resolvers>
</mvc:annotation-driven>
@ck1125
ck1125 / MessageConvertersConfig.groovy
Created August 7, 2012 20:03
messageConverters bean
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.http.converter.ByteArrayHttpMessageConverter
import org.springframework.http.converter.HttpMessageConverter
import org.springframework.http.converter.StringHttpMessageConverter
import org.springframework.http.converter.json.MappingJacksonHttpMessageConverter
import org.springframework.http.converter.xml.Jaxb2RootElementHttpMessageConverter
import org.springframework.http.converter.xml.SourceHttpMessageConverter
import org.springframework.http.converter.xml.XmlAwareFormHttpMessageConverter
import org.springframework.stereotype.Component