Skip to content

Instantly share code, notes, and snippets.

View elaatifi's full-sized avatar
💭
I may be slow to respond.

Sidi Mohamed ELAATIFI elaatifi

💭
I may be slow to respond.
View GitHub Profile
@elaatifi
elaatifi / unhex.sql
Created May 4, 2023 15:38
SQLite unhex, how to convert a hex string back to number
SELECT CAST(x'||hex_string AS INTEGER) AS int_value
FROM hex_values;
@elaatifi
elaatifi / drop_all_objects.sql
Created November 18, 2018 15:28
Drop all database objects for PostgreSQL
CREATE OR REPLACE FUNCTION drop_all_objects() RETURNS VOID AS
$$
DECLARE
rd_object RECORD;
v_idx_statement VARCHAR(500);
BEGIN
-- 1. Dropping all stored functions
RAISE NOTICE '%', 'Dropping all stored functions...';
["AbstractPage.restrictions","AbstractPage.contentSlots","ContentSlotForPage.contentSlot","ContentSlot.cmsComponents","AbstractCMSComponentContainer.simpleCMSComponents","AbstractCMSComponentContainer.currentCMSComponents","RotatingImagesComponent.banners","AbstractCMSComponent.restrictions","PrintStampPush3ColsComponent.bannersPrintStamp","LetterPush3ColsComponent.banners","ColisPush3Component.banners","SliderComponent.slides","CGVItemsForCGVComponent.cgvItems","LetterSliderComponent.slides","SildesForLetterSliderComponent.slides","PrintStampSliderComponent.slidesStamp","EboutiqueLinksListComponent.linkItems","EboutiqueBannersListComponent.bannerItems","FonctionnalitePushListComponent.fonctionnalitePush","ServicePushListComponent.servicePush","CMSParagraphForListRelation.cmsParagraph","SearchEServicePushListComponent.searchEservicePush","EboutiqueFarandoleComponent.tabs","EboutiqueFarandoleComponent.banner ","EboutiqueTabComponent.farandoles ","EboutiqueAbstractAutopromoComponent.leftSectio
@elaatifi
elaatifi / LocalizedStringTestCases.java
Created April 17, 2017 13:15
hybris has a special setters and getters for Localized propertires, where getter & setters have an additional Locale parameter. The following test case show an example of how to map this kind of properties to Map where the key is the local with default auto mapping
public class LocalizedStringTestCases {
ConfigurableMapper mapper = new ConfigurableMapper() {
@Override
protected void configure(MapperFactory factory) {
factory.classMap(ProductModel.class, ProductDTO.class).byDefault().register();
}
@elaatifi
elaatifi / App.java
Created December 17, 2015 20:04
Playing with Orika and Mongo
package mongo.mongo;
import java.util.Arrays;
import java.util.List;
import com.mongodb.DB;
import com.mongodb.DBCollection;
import com.mongodb.DBObject;
import com.mongodb.MongoClient;

Latency numbers every programmer should know

L1 cache reference ......................... 0.5 ns
Branch mispredict ............................ 5 ns                     on recent CPU
L2 cache reference ........................... 7 ns                     14x L1 cache
Mutex lock/unlock ........................... 25 ns
Main memory reference ...................... 100 ns                     20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy ............. 3,000 ns  =   3 µs
Send 2K bytes over 1 Gbps network ....... 20,000 ns  =  20 µs
SSD random read ........................ 150,000 ns  = 150 µs

Read 1 MB sequentially from memory ..... 250,000 ns = 250 µs 4X memory

@elaatifi
elaatifi / CustomPropertyResolver.java
Created October 10, 2014 22:41
External configuration of non generic collection in Orika
import java.lang.reflect.Method;
import java.util.Properties;
import ma.glasnost.orika.metadata.Type;
import ma.glasnost.orika.metadata.TypeFactory;
import ma.glasnost.orika.property.IntrospectorPropertyResolver;
public class CustomPropertyResolver extends IntrospectorPropertyResolver {
private Properties props;
@elaatifi
elaatifi / gist:8297e56e9b51bd114c4c
Created August 6, 2014 10:41
Latency Comparison Numbers
Latency Comparison Numbers
--------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns
Send 1K bytes over 1 Gbps network 10,000 ns 0.01 ms
Read 4K randomly from SSD* 150,000 ns 0.15 ms
@elaatifi
elaatifi / MyClassMapBuilder.java
Created January 8, 2014 14:14
The important method in this class is passTest which will decide if we include a fieldMap or excluded it.
public static class MyClassMapBuilder<A,B> extends ClassMapBuilder<A,B> {
protected MyClassMapBuilder(Type<A> aType, Type<B> bType,
MapperFactory mapperFactory,
PropertyResolverStrategy propertyResolver,
DefaultFieldMapper[] defaults) {
super(aType, bType, mapperFactory, propertyResolver, defaults);
}
/* (non-Javadoc)
* @see ma.glasnost.orika.metadata.ClassMapBuilder#addFieldMap(ma.glasnost.orika.metadata.FieldMap)
@elaatifi
elaatifi / CaseInsensitiveClassMapBuilder.java
Created October 16, 2013 15:40
CaseInsensitiveClassMapBuilder is an extension of ClassMapBuilder which performs case-insensitive matching of property names in the 'byDefault()' method.
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Map.Entry;
import ma.glasnost.orika.DefaultFieldMapper;
import ma.glasnost.orika.MapperFactory;
import ma.glasnost.orika.property.PropertyResolverStrategy;