Skip to content

Instantly share code, notes, and snippets.

View fujohnwang's full-sized avatar
🌓
儒释道法自然

王福强 fujohnwang

🌓
儒释道法自然
View GitHub Profile
@fujohnwang
fujohnwang / gist:1315137
Created October 26, 2011 01:28
memory barrier demo
/**
* Project File of Scala, Right Reserved by Darren Studio Works
* <p/>
* User: fujohnwang
* Date: 10/26/11
*/
public class SharedObject {
public int age;
public String name;
public boolean married;
@fujohnwang
fujohnwang / gist:3081819
Created July 10, 2012 07:29
hack mysql jdbc driver to send raw command
Class.forName("com.mysql.jdbc.Driver")
val connection = DriverManager.getConnection("jdbc:mysql://10.20.142.140/", "darren", "")
try {
val command = ComBinlogDump("mysql-bin.000001", 4L, 111)
val buffer = connection.asInstanceOf[JDBC4Connection].getIO.sendCommand(MysqlDefs.COM_BINLOG_DUMP, null, command.toMysqlBuffer(), false, null, 0)
println("buffer.getPosition=" + buffer.getPosition)
println("buffer.getBufLength=" + buffer.getBufLength)
println(buffer.dump())
} finally {
connection.close()
@fujohnwang
fujohnwang / 0_reuse_code.js
Created June 15, 2014 01:55
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@fujohnwang
fujohnwang / gist:f1e0522f74335e25aaf1
Last active August 29, 2015 14:04
credit card number validation
class CreditCardValidator {
@BeanProperty
var cardNumberLength = 16
def validate(cardNumber: String): Boolean = {
val numberString = StringUtils.deleteWhitespace(cardNumber)
if (numberString.length != cardNumberLength) return false
if (!StringUtils.isNumeric(numberString)) return false
val digits = numberString.map(c => java.lang.Byte.valueOf(String.valueOf(c)))
val total = digits.zipWithIndex.foldLeft(0)((total, e) => if (e._2 % 2 != 0) total + e._1 else total + doubleFlat(e._1))
@fujohnwang
fujohnwang / gist:33f8476c447c9fc747e2
Created August 22, 2014 10:04
Simple Purposed Kafka Producer
trait Messenger {
def send(topic: String, message: String): Unit
def send(topic: String, messageKey: String, messageBody: String): Unit
}
class KafkaMessenger(producer: Producer[String, String]) extends Messenger {
override def send(topic: String, message: String): Unit = send(topic, null, message)
override def send(topic: String, messageKey: String, messageBody: String): Unit = {
@fujohnwang
fujohnwang / gist:b994a74e15d0e448e8ef
Created October 13, 2014 03:06
msgpack and http accessor sample code
/**
* Hello world!
*/
public class App {
public static void main(String[] args) {
Logger logger = LoggerFactory.getLogger("App");
Thread.currentThread().setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
@Override
public void uncaughtException(Thread t, Throwable e) {
System.out.println("-----------------------we got here?");
@fujohnwang
fujohnwang / gist:4acd9183350767d06438
Created October 22, 2014 07:38
lombok maven config
<properties>
<compiler.version>1.6</compiler.version>
<java_source_version>1.6</java_source_version>
<java_target_version>1.6</java_target_version>
<file_encoding>UTF-8</file_encoding>
</properties>
<build>
<finalName>test</finalName>
<plugins>
@fujohnwang
fujohnwang / run-ansible-with-any-host-without-inventory
Created December 17, 2019 03:23 — forked from lilongen/run-ansible-with-any-host-without-inventory
How to run Ansible without specifying the inventory but the host directly?
Question:
. How to run Ansible without specifying the inventory but the host directly?
. Run a playbook or command with arbitrary host not in the inventory hosts list?
. run ansible with arbitrary host/ip without inventory?
Answer:
Surprisingly, the trick is to append a ,
The host parameter preceding the , can be either a hostname or an IPv4/v6 address.
ansible all -i example.com,
@fujohnwang
fujohnwang / 2020-04-02T10:21:06
Last active April 2, 2020 02:39
microblog of mine, since weibo or twitter is out of control ;0)
哪有什么岁月静好,无非是有人替你寻衅滋事罢了,比如老罗与暖气片的故事
type D=Double;def w(x:D,y:D,a:D)={val(i,j)=(x-a,y-8);Math.sqrt(i*i+j*j)< 8};val l:Stream[Char]="love".toStream#:::l;val c=l.toIterator;def p(b:Boolean)=print(if(b)c.next else' ');for(y<-0 to 24){for(x<-0 to 32){if(y>7)p((16-x).abs< 24-y)else p(w(x,y,8)|w(x,y,24))};println}