Skip to content

Instantly share code, notes, and snippets.

View kevinlynx's full-sized avatar

kevinlynx kevinlynx

View GitHub Profile
@kevinlynx
kevinlynx / implicit.scala
Last active December 24, 2015 21:39
implicit parameter
// `s' and `b' are both implicit parameters
def implFn(i: Int)(implicit s: String, b: Int) = {
println(s)
i + b
}
def main(args: Array[String]) {
// otherS will match parameter `s' by type, **not by name**
implicit val otherS = "hello"
// error, two variables with the same type
@kevinlynx
kevinlynx / gen_runjar.bat
Last active December 23, 2015 19:39
create a shell script to run jar specified some jars as class path
echo off
REM
REM Usage: put jars into lib/ext directory, put config file in ext directory
REM gen_runjar.bat
REM Kevin Lynx 09/24/2013
REM
if "%1"=="" goto usage
if not "%1"=="clear" goto dist
del /Q ext\*.*
#include <assert.h>
char find(const char *str) {
int cnt = 1;
char c = *str++;
for ( ; *str; ++str) {
c = cnt == 0 ? *str : c;
cnt = cnt + (*str == c ? 1 : (cnt - 1 < 0 ? -cnt : -1));
}
return cnt > 0 ? c : 0;
#include <assert.h>
typedef unsigned __int64 uint64;
typedef unsigned char byte;
void setBit(byte *data, int pos) {
byte bits[] = {
0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01
};
/* note the position starts from 1, not 0 */
@kevinlynx
kevinlynx / start_match.cpp
Created August 12, 2013 13:24
match a string using `*' operator i.e: *abc, a*bc
// test.cpp : 定义控制台应用程序的入口点。
//
#include <stdio.h>
#include <vector>
#include <string>
#include <assert.h>
struct OpCode {
/* 0: indicate `*' operator, 1: string match */
@kevinlynx
kevinlynx / gist:3413212
Created August 21, 2012 07:47
chat server
class Entity {
public:
enum { CLIENT, SERVER };
Entity(const CGUID &id, int type, const std::string &brief);
// send text to this entity, this function will preprocess `text`
bool Send(const std::string &text);
private:
@kevinlynx
kevinlynx / poster.rb
Last active September 12, 2017 13:59
#!/usr/bin/env ruby
#
# I write this script to post my personl blog codemacro.com posts to my cppblog.com/kevinlynx
# Kevin Lynx 8.7.2012
#
require 'nokogiri'
require 'open-uri'
require 'xmlrpc/client'
require 'yaml'