Skip to content

Instantly share code, notes, and snippets.

View xie-qianyue's full-sized avatar

XIE Qianyue xie-qianyue

  • NetEase
  • Hangzhou
View GitHub Profile
@xie-qianyue
xie-qianyue / common.lib
Created July 25, 2018 11:20
rename the suffix
# common.lib
# Note no #!/bin/sh as this should not spawn
# an extra shell.
STD_MSG="About to rename some files..."
rename()
{
# expects to be called as: rename .txt .bak
FROM=$1
@xie-qianyue
xie-qianyue / magic_number.sh
Created July 22, 2018 05:30
grep return value and /dev/null redirection
echo -en "Please guess the magic number: "
read X
echo $X | grep "[^0-9]" > /dev/null 2>&1
if [ "$?" -eq "0" ]; then
# If the grep found something other than 0-9
# then it's not an integer.
echo "Sorry, wanted a number"
else
# The grep found only 0-9, so it's an integer.
# We can safely do a test on it.
@xie-qianyue
xie-qianyue / test_if.sh
Created July 21, 2018 10:43
test if shell script
#!/bin/sh
if [ "$X" -lt "0" ]
then
echo "X is less than zero"
fi
if [ "$X" -gt "0" ]; then
echo "X is more than zero"
fi
[ "$X" -le "0" ] && \
echo "X is less than or equal to zero"
@xie-qianyue
xie-qianyue / PersonBeanDefinitionRegistryPostProcessor.java
Created June 21, 2018 06:09
Using BeanDefinitionRegistryPostProcessor to register bean
@Component
@Slf4j
public class PersonBeanDefinitionRegistryPostProcessor
implements BeanDefinitionRegistryPostProcessor {
@Override
public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry)
throws BeansException {
// 注册Bean定义,容器根据定义返回bean
log.info("register personManager1>>>>>>>>>>>>>>>>");
@xie-qianyue
xie-qianyue / DevLBRule.java
Created June 15, 2018 05:58
custom routing rule for Ribbon
public class DevLBRule extends AbstractLoadBalancerRule {
@Value("${some.ip.prefix}")
private String ipPrefix = "10.20.";
@Override
public void initWithNiwsConfig(IClientConfig iClientConfig) {
}
@xie-qianyue
xie-qianyue / BeanFactoryPostProcessorExample.java
Created June 11, 2018 09:49
Spring - Register bean by BeanFactoryPostProcessor
public class BeanFactoryPostProcessorExample {
public static void main (String[] args) {
AnnotationConfigApplicationContext context =
new AnnotationConfigApplicationContext(MyConfig.class);
MyBean bean = context.getBean(MyBean.class);
bean.doSomething();
}
}
@xie-qianyue
xie-qianyue / BeanDefinitionBuilderExample.java
Last active June 11, 2018 09:28
Spring - Register bean by BeanDefinitionBuilder
public class BeanDefinitionBuilderExample {
public static void main (String[] args) {
DefaultListableBeanFactory beanFactory =
new DefaultListableBeanFactory();
BeanDefinitionBuilder b =
BeanDefinitionBuilder.rootBeanDefinition(MyBean.class)
.addPropertyValue("str", "myStringValue");
@xie-qianyue
xie-qianyue / GenericBeanDefinitionExample.java
Created June 11, 2018 09:25
Spring - Register Bean by GenericBeanDefinition
public class GenericBeanDefinitionExample {
public static void main (String[] args) {
DefaultListableBeanFactory context =
new DefaultListableBeanFactory();
GenericBeanDefinition gbd = new GenericBeanDefinition();
gbd.setBeanClass(MyBean.class);
MutablePropertyValues mpv = new MutablePropertyValues();
function foo() {
var f = (...args) => args[0];
return f(2);
}
console.log(foo()); // 2
@xie-qianyue
xie-qianyue / arrowThis.js
Last active April 8, 2016 14:42
Binding this in callback
function Person(){
this.age = 0;
setInterval(() => {
this.age++; // |this| properly refers to the person object
console.log(this.age); // 1 2 3 ...
}, 1000);
}
var p = new Person();