Skip to content

Instantly share code, notes, and snippets.

View CaglarGonul's full-sized avatar

ccocoo CaglarGonul

View GitHub Profile
@CaglarGonul
CaglarGonul / Login.java
Created March 15, 2013 23:27
Fun with Electroserver, Hibernate and Thread Pool
package com.cgon.loginmodule;
import com.electrotank.electroserver5.extensions.BaseLoginEventHandler;
import com.electrotank.electroserver5.extensions.ChainAction;
import com.electrotank.electroserver5.extensions.LoginContext;
import com.electrotank.electroserver5.extensions.api.UserServerVariableResponse;
import com.electrotank.electroserver5.extensions.api.value.EsObject;
import com.electrotank.electroserver5.extensions.api.value.EsObjectRO;
public class Login extends BaseLoginEventHandler{
@CaglarGonul
CaglarGonul / lastextension.xml
Created March 15, 2013 23:28
Fun with Electroserver, Hibernate and Thread Pool
<?xml version="1.0" encoding="utf-8" ?>
<Extension>
<Name>FunES</Name>
<EventHandlers>
<LoginHandlers>
<LoginHandler>
<Handle>Login</Handle>
<Type>Java</Type>
<Path>com.cgon.loginmodule.Login</Path>
</LoginHandler>
@CaglarGonul
CaglarGonul / test.as
Created March 15, 2013 23:28
Fun with Electroserver, Hibernate and Thread Pool
package {
import com.electrotank.electroserver5.api.ConnectionResponse;
import com.electrotank.electroserver5.api.EsObject;
import com.electrotank.electroserver5.api.LoginRequest;
import com.electrotank.electroserver5.api.LoginResponse;
import com.electrotank.electroserver5.api.MessageType;
import com.electrotank.electroserver5.api.PluginMessageEvent;
import com.electrotank.electroserver5.api.PluginRequest;
import com.electrotank.electroserver5.connection.AvailableConnection;
import com.electrotank.electroserver5.connection.TransportType;
@CaglarGonul
CaglarGonul / max.sml
Last active December 15, 2015 09:09
A simple selection algorithm for finding the maximum integer option in an integer list is given below :
fun max_case (xs) =
case xs of
[] => NONE
| x::xs' => let fun non_empty_max (ys) =
case ys of
[] => x
| y::ys' => let val tl_ans = non_empty_max (ys')
in
if y > tl_ans
then y
@CaglarGonul
CaglarGonul / remdup.sml
Last active December 15, 2015 09:09
A simple ML algorithm for removing duplicates in a list is given below :
fun remove_duplicates (xs) =
case xs of
[]=>[]
| x::xs' => if List.exists (fn y=> x=y) xs'
then remove_duplicates (xs')
else x::remove_duplicates (xs')
val test_remove_duplicates = remove_duplicates ([3,3,3,3,5,5,5,5,6,6,6,6,7])
@CaglarGonul
CaglarGonul / mycb.sml
Last active December 15, 2015 17:19
A callback implementation in ML.
(*We need a mutable list to store the list of registered callbacks.*)
(*The initial list will be empty.*)
val cbs : (int -> unit) list ref = ref []
(*We need a public function to register the callbacks on the the callback list*)
fun registerCallBack f =
cbs := f::(!cbs)
(*When a specific action occurs we will call this function.*)
(*This function will call each call back with a parameter.*)
@CaglarGonul
CaglarGonul / 1.Func.java
Last active December 15, 2015 20:48
Playing with closures in Java7. Thanks to Prof. Grossman.
package com.fs;
/**
* This interface is responsible for holding the closures when it comes to map.
* It uses two generic types. One for the argument and one for the return type.
* @param <B> Generic type
* @param <A> Generic type
*/
public interface Func<B,A> {
/**
@CaglarGonul
CaglarGonul / 1.CallBack.java
Last active December 15, 2015 20:49
Callback implementation in Java7
package com.fs;
public interface CallBack {
void m(int e);
}
@CaglarGonul
CaglarGonul / 1.Animal.java
Created April 6, 2013 08:43
Programming to an interface rather than an implementation.
package com.chp1.simuduck.v3;
public interface Animal {
void makeSound();
}
@CaglarGonul
CaglarGonul / 1.WeaponBehaviour.java
Last active December 15, 2015 21:29
The Strategy Pattern : It defines a family of algorithms, encapsulates each one, and makes them interchangeable. Strategy lets the algorithm vary independently from clients that use it.
package com.chp1.designpuzzle;
public interface WeaponBehaviour {
String useWeapon();
}