Skip to content

Instantly share code, notes, and snippets.

View galak-fyyar's full-sized avatar
🍊

Anatoliy Sokolenko galak-fyyar

🍊
View GitHub Profile
@galak-fyyar
galak-fyyar / ChallengeLoader.as
Created October 12, 2011 10:25
Implementing support of curry operation in Flex
public class ChallengeLoader extends EventDispatcher {
public function loadWordSound( wordSoundUrl:String, onSuccess:Function,
onError:Function ):void {
var loadingProcessData:LoadingProcessData = new LoadingProcessData( onSuccess,
onError );
var loadingEventProcessor:Function = FunctionUtils.curry(
onCompleteResourceLoad, loadingProcessData );
var wordSound:Sound = new Sound();
@galak-fyyar
galak-fyyar / CrashThread.java
Created October 13, 2011 14:15
Crash test for JVM that creates unlimited number of threads
import java.util.*;
import java.text.*;
class CrashThread extends Thread {
public static final long BYTES_IN_MEGABYTE = 1024 * 1024;
public static void main(String[] a) throws Throwable {
try {
System.out.println("Maximum possible heap size is " + Runtime.getRuntime().max Memory() / BYTES_IN_MEGABYTE);
@galak-fyyar
galak-fyyar / ForBug.java
Created October 13, 2011 18:59
Weird bug in Java(TM) SE Runtime Environment (build 1.6.0_27-b07) Java HotSpot(TM) 64-Bit Server VM (build 20.2-b06, mixed mode)
import java.util.*;
class ForBug {
public static void main( String[] a ) {
int m = Integer.MAX_VALUE;
for ( int n = 1; n <= m; n++ ) {
System.out.println( "Step " + n );
}
}
@galak-fyyar
galak-fyyar / pom.xml
Created October 19, 2011 09:25
Generating XML Shema from POJO using Maven
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<phase>generate-resources</phase>
<goals>
<goal>run</goal>
</goals>
@galak-fyyar
galak-fyyar / opends.ldif
Created October 19, 2011 09:39
Managing schemas of LDAP servers
dn: cn=schema
changetype: modify
add: objectClasses
objectClasses: ( 1.3.6.1.4.1.26037.1.999.2000
NAME ( 'blogger' )
DESC 'Someone who has a blog'
SUP inetOrgPerson
STRUCTURAL
MAY blog
X-ORIGIN 'OpenDS Directory Server'
@galak-fyyar
galak-fyyar / ServiceFactoryImpl_Buggy.java
Created October 19, 2011 11:24
Wrong way to synchronize factory method
public class ServiceFactoryImpl_Buggy<T extends Service> {
protected Map<String, T> serviceMap = new HashMap<String, T>();
public T getService( String name ) {
T result = serviceMap.get( name );
if ( null == result ) {
synchronized ( this ) {
result = createService( name );
serviceMap.put( name, result );
@galak-fyyar
galak-fyyar / DateService.java
Created October 19, 2011 11:33
GWT and Spring Framework 3.0 integration
import java.util.Date;
public interface DateService {
Date getCurrentTime();
}
@galak-fyyar
galak-fyyar / gist:1298111
Created October 19, 2011 12:07
GWT asynchromious load
GWT.runAsync( new RunAsyncCallback() {
public void onFailure( Throwable caught ) {
Window.alert( "Code download failed" );
}
public void onSuccess() {
Window.alert( "Hello, async callback" );
}
} );
@galak-fyyar
galak-fyyar / gist:1298123
Created October 19, 2011 12:15
Platform dependent settings in Spring
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="nullValue" value="null"/>
<property name="ignoreResourceNotFound" value="true"/>
<property name="locations">
<list>
<value>classpath:/application.properties
<value>classpath:/application-#{ systemEnvironment[ 'SUPER_APP_ENV' ] }.properties
</list>
</property>
</bean>
@galak-fyyar
galak-fyyar / A_Correct.java
Created October 19, 2011 12:24
Working with exceptions in Java
public String getUnreadMessages() {
List<Message> messages = service.getMessage().getUnreadMessage();
String result = convert( messages );
markMessagesUpdated( messages );
return result;
}