Friday, June 30, 2017

AB Testing with Local Storage and Google Analytics

Leave a Comment
I'm running a sitewide AB test on my ecommerce site. After a visitor lands, I assign them a local storage key/value: function isLocalStorageNameSupported() { var testKey = 'test', storage = window.localStorage; try { storage.setItem(testKey, '1'); storage.removeItem(testKey); return true; } catch (error) { return false; } } $(function() { if(isLocalStorageNameSupported()){ var version = Cookies.get("version"); if (version == null) { if (Math.random() >= 0.5){ ...
Read More

How can I quickly enumerate directories on Win32?

Leave a Comment
I'm trying to speedup directory enumeration in C++, where I'm recursing into subdirectories. I currently have an app which spends 95% of it's time in FindFirst/FindNextFile APIs, and it takes several minutes to enumerate all the files on a given volume. I know it's possible to do this faster because there is an app that does: Everything. It enumerates my entire drive in seconds. How might I accomplish something like this? 6 AnswersAnswers 1 I realize this is an old post, but there is a project on source forge that...
Read More

Java Hibernate org.hibernate.exception.SQLGrammarException: could not extract ResultSet on createSQLQuery

Leave a Comment
I have this method. private final void updateAllTableFields(final Class clazz){ final String tableName = ((Table)clazz.getAnnotation(Table.class)).name(); final String sqlQuery = new StringBuilder("SET @ids = NULL; ") .append("UPDATE ") .append(tableName) .append(' ') .append("set activeRecord=:activeRecord ") .append("where activeRecord=true and updateable=true ") .append("and (SELECT @ids \\:= CONCAT_WS(',', id, @ids)); ") .append("select...
Read More

Thursday, June 29, 2017

.HTACCESS Redirection Issues

Leave a Comment
Namely, I have this .htaccess command... RewriteCond %{REQUEST_FILENAME} -f [OR] RewriteCond %{REQUEST_FILENAME} -d RewriteRule ^ - [L] RewriteRule ^([^\x00-\x7F]+).*$ ?open=encyclopedia&letter=$1&term=$0 [R,B,L,QSA] RewriteRule ^([A-Z](?:[^\x00-\x7F]+|[A-Z])?).*$ ?open=encyclopedia&letter=$1&term=$0 [R,B,L,QSA] ...And I have two issues with it now: Issue 1 - It loads shorthand of all of the letters except A, S and O. It displays blank white page instead of the actual page. Issue 2 - When I enter http://example.com/Šandi...
Read More

Android microphone constantly gives 32639 or -32640 on newer devices

Leave a Comment
I've implemented code similar to this. I have a noise alert go off in the Log, but it always gives 32639 or -32640 regardless of what kind of noise is going on outside. short[] buffer = new short[minSize]; boolean thresholdMet = false; int threshold = sliderThreshold.getProgress(); ar.read(buffer, 0, minSize); //Iterate through each chunk of amplitude data //Check if amplitude is greater than threshold for (short s : buffer) { if (Math.abs(s) > threshold) { thresholdMet = true; Log.w("NoiseThreshold",...
Read More

Firebase multi-tenancy with play framework depends on header value of HTTP request

Leave a Comment
I have a play framework project that provides APIs that shared between multiple front-ends, currently, I'm working on single front-end but I want to create a multi-tenant backend, each front-end got its own Firebase account. My problem that I have to consider which firebase project to access depends on the request header value, that came with different values depends on the front end. What I have now: FirebaseAppProvider.java: public class FirebaseAppProvider implements Provider<FirebaseApp> { private final...
Read More

Module using another function of the same module

Leave a Comment
I have something like this: MyModule index.js myFunction1.js myFunction2.js In index.js file i'm exporting all modules function (myFunction1 and myFunction2). But, in myFunction2 I use myFunction1. If I import the index (all the module) and call it like MyModule.myFunction1 inside myFunction2, I get an error (function does not exists). If I import myFunction1.js and call it like myFunction1(), I can't make an Stub of it when I'm going to test it. Any aproach to do something like this? 6 AnswersAnswers 1 //////////////////////...
Read More

How to prevent checkboxes and dropdowns in a div to be scaled in safari

Leave a Comment
I have a div which contains some elements. I want the div to be scaled when it is hovered upon. It works fine in chrome but something weird happens in safari. The checkboxes and dropdowns are also getting scaled. How can I fix it in safari? .box:hover { transform: scale(1.03); -ms-transform: scale(1.03); -webkit-transform: scale(1.03); -webkit-transition: all .01s ease-in-out; transition: all .01s ease-in-out; } div { padding-left: 30px; margin: 10px; } .box { border: 1px solid black;...
Read More

Using the Django ORM, How can you create a unique hash for all possible combinations

Leave a Comment
I want to maintain a Django model with a unique id for every combination of choices within the model. I would then like to be able to update the model with a new field and not have the previous unique id's change. The id's can be a hash or integer or anything. What's the best way to achieve this? class MyModel(models.Model): WINDOW_MIN = 5 WINDOW_MAX = 7 WINDOW_CHOICES = [(i,i) for i in range(WINDOW_MIN - 1, WINDOW_MAX - 1)] window = models.PositiveIntegerField('Window', editable=True, default=WINDOW_MIN,...
Read More

Improving performance of hive jdbc

Leave a Comment
Does aynyone know how to increase performance for HIVE JDBC connection. Detailed problem: When I query hive from Hive CLI, I get a response within 7 sec but from HIVE JDBC connection I get a response after 14 sec. I was wondering if there is any way (configuration changes) with which I can improve performance for query through JDBC connection. Thanks in advance. 2 AnswersAnswers 1 Can you please try the below options. If your query has joins then try setting the hive.auto.convert.join to true. Try changing the...
Read More

Modifing metadata from existing phAsset seems not working

Leave a Comment
In my App I want to make it possible, that the user sets an StarRating from 0 to 5 for any Image he has in his PhotoLibrary. My research shows, that there are a couple of ways to get this done: Save the exif metadata using the new PHPhotoLibrary Swift: Custom camera save modified metadata with image Writing a Photo with Metadata using Photokit Most of these Answers were creating a new Photo. My snippet now looks like this: let options = PHContentEditingInputRequestOptions() options.isNetworkAccessAllowed = true self.requestContentEditingInput(with:...
Read More

Wednesday, June 28, 2017

Tree view header inside add the dropdown menu in odoo 8 using js and python

Leave a Comment
Tree view header inside add the dropdown menu in odoo 8 using js and python I am use odoo-8. My question is how to add the dropdown menu above side on tree view in odoo8 using JS and python. And I want to dynamically show the all the category of products in this drop-down menu. And when i click on the particular category so, tree view inside sort particular clickable types of products. i.e Suppose click on the Mobile category...
Read More

c# Make some tasks asynchronous

Leave a Comment
My Code: ConcurrentQueue<string> concurrentQueue = new ConcurrentQueue<string>(); private void Form1_Load(object sender, EventArgs e) { try { var task1 = Task.Run(() => GetMessages()); var task2 = Task.Run(() => GetOrderBookData()); UpdateOrderBook(); } catch(Exception ex) { MessageBox.Show(ex.Message); } } private void GetMessages() { var w = new WebSocketConfiguration(); //class to connect o websocket to get messages w.OnWSOpen += w_OnWSOpen; w.OnWSMessage += w_OnWSMessage;...
Read More

WkHtmlToPdf grey border around images

Leave a Comment
I'm creating a PDF using the Wkhtmltopdf library. Everything is working fine, except one little detail: I overlap two images with transparent background to another background image. This is the result: The background image is the one with the trees and the sky, each character is in a different image with transparent background. So the result is quite perfect except for the grey border around each person. Is it possible to remove...
Read More

Matplotlib animation not showing

Leave a Comment
When I try this on my computer at home, it works, but not on my computer at work. Here's the code import numpy as np import matplotlib.pyplot as plt import matplotlib.animation as animation import sys import multiprocessing def update_line(num, gen, line): data = gen.vals_queue.get() data = np.array(data) line.set_data(data[..., :num]) return line, class Generator(multiprocessing.Process): def __init__(self): self.vals = [[], []] super(Generator, self).__init__() self.vals_queue...
Read More

How failover works on Google Cloud SQL?

Leave a Comment
I intend to connect a PHP app (from a server outside Googel Cloud Platform) to Google Cloud SQL. I want to know how can I design the app to failover its database properly. According to the manual: When a zonal outage occurs and your master fails over to your failover replica, any existing connections to the instance are closed. However, your application can reconnect using the same connection string or IP address; you do not need to update your application after a failover. It appears everything is happenning...
Read More

Logging lots of Android sensor data

Leave a Comment
I have an Android application that is logging several Android sensors at approximately 100Hz. So if i am logging 10 sensors, I am writing about 3000 data points per second to a file (each sensor typically has 3 entries). Now the problem is that i want to minimize the effect of this writing on the rest of the app. Specifically, I do not want the logging to slow down event delivery... i want to make sure that i am getting events as soon as they happen, and not with a delay (i know there will always be some delay because Android...
Read More

How to make text in <meter> tag visible over the meter

Leave a Comment
Given the html <meter value="0.55" high="0.999" optimum="1"> <span class="meter-value">0.5491</span> </meter> I would like text 0.5491 on top of the meter. I tried to style the text using usual CSS techniques, but it won't show at all. In inspector it just says width and height is 0 no matter how much I say things like .meter-value { display: block; width: 50px; height: 20px; } I made more attempts, these examples are simplified. I use Firefox for tests and compatibility is not pressing...
Read More

How to define the Cache-Control header on an S3 object via a signed URL?

Leave a Comment
Following the instructions in this guide, I've managed to get uploads working via signed URLs. It looks something like this: const s3 = new aws.S3(); const s3Params = { Bucket: S3_BUCKET, Key: fileName, Expires: 60, ContentType: fileType, ACL: 'public-read', CacheControl: 'public, max-age=31536000', }; s3.getSignedUrl('putObject', s3Params, (err, data) => { // ... }); ...except my CacheControl param (which I added myself; it isn't in the guide) does not seem to take effect. When I use the above code...
Read More