Keeping track of interesting places I put my feet on in the software development world.
Search This Blog
Tuesday, December 24, 2019
Saturday, December 21, 2019
Singleton, Decorator and Command design patterns (well) explained with (good) examples
An article that stands out of google search first results. Worth checking!
https://www.freecodecamp.org/news/the-basic-designs-patterns-all-developers-need-to-know/
https://www.freecodecamp.org/news/the-basic-designs-patterns-all-developers-need-to-know/
Sunday, December 15, 2019
Create circle with google map api with mousemove event to enlarge / shrink area
function addCircle_new(lat, lng, radius, alreadyDrawn) {
function createCircle(lat, lng, radius) {
var coordinates = new google.maps.LatLng(lat, lng);
var options = {
strokeColor: '#910000',
strokeOpacity: 0.5,
strokeWeight: 1,
fillColor: '#FC7341',
fillOpacity: 0.35,
map: map,
center: coordinates,
radius: radius
};
// Add the circle for this city to the map.
circle = new google.maps.Circle(options);
return circle;
}
var circle;
if (alreadyDrawn) {
circle = createCircle(lat, lng, radius * 1000);
drawObject = circle;
pois.push(circle);
}
else {
//google.maps.event.removeListener(clickListener);
google.maps.event.addListenerOnce(map, 'click', function (x) {
//circle = createCircle(x.latLng.lat(), x.latLng.lng(), radius * 1000);
circle = createCircle(lat, lng, radius * 1000);
var clickEventParameters = x;
var mouseMoveEventParameters;
var mouseMove = google.maps.event.addListener(map, 'mousemove', function (y) {
mouseMoveEventParameters = y;
var xOffset = mouseMoveEventParameters.qa.x - clickEventParameters.qa.x;
var yOffset = mouseMoveEventParameters.qa.y - clickEventParameters.qa.y;
var radiusOffset = Math.sqrt(Math.pow(xOffset, 2) + Math.pow(yOffset, 2)) * 100000;
circle.setRadius(radiusOffset);
});
var dblClick = google.maps.event.addListener(map, 'dblclick', function (w) {
drawObject = circle;
google.maps.event.removeListener(mouseMove);
pois.push(circle);
//clickListener = google.maps.event.addListener(map, 'click', map_MouseClick);
});
});
}
}
function createCircle(lat, lng, radius) {
var coordinates = new google.maps.LatLng(lat, lng);
var options = {
strokeColor: '#910000',
strokeOpacity: 0.5,
strokeWeight: 1,
fillColor: '#FC7341',
fillOpacity: 0.35,
map: map,
center: coordinates,
radius: radius
};
// Add the circle for this city to the map.
circle = new google.maps.Circle(options);
return circle;
}
var circle;
if (alreadyDrawn) {
circle = createCircle(lat, lng, radius * 1000);
drawObject = circle;
pois.push(circle);
}
else {
//google.maps.event.removeListener(clickListener);
google.maps.event.addListenerOnce(map, 'click', function (x) {
//circle = createCircle(x.latLng.lat(), x.latLng.lng(), radius * 1000);
circle = createCircle(lat, lng, radius * 1000);
var clickEventParameters = x;
var mouseMoveEventParameters;
var mouseMove = google.maps.event.addListener(map, 'mousemove', function (y) {
mouseMoveEventParameters = y;
var xOffset = mouseMoveEventParameters.qa.x - clickEventParameters.qa.x;
var yOffset = mouseMoveEventParameters.qa.y - clickEventParameters.qa.y;
var radiusOffset = Math.sqrt(Math.pow(xOffset, 2) + Math.pow(yOffset, 2)) * 100000;
circle.setRadius(radiusOffset);
});
var dblClick = google.maps.event.addListener(map, 'dblclick', function (w) {
drawObject = circle;
google.maps.event.removeListener(mouseMove);
pois.push(circle);
//clickListener = google.maps.event.addListener(map, 'click', map_MouseClick);
});
});
}
}
Monday, December 9, 2019
Elasticsearch aggregation - show aggregations only + overcome default limitation of aggregated buckets
Elasticsearch aggregation - output showing only aggregated field + overcoming default limitation of aggregated values (in this case, set to 1000)
GET customer_success_reports/_search
{
"size":0,
"aggs" : {
"Country": {
"composite" : {
"size": 1000,
"sources" : [
{ "country": { "terms" : { "field": "Meta.GeoInfo.Country.keyword","missing_bucket": true } } }
]
}
}
}
}
size:0 -> makes the output show the aggregated buckets only instead of the whole documents
GET customer_success_reports/_search
{
"size":0,
"aggs" : {
"Country": {
"composite" : {
"size": 1000,
"sources" : [
{ "country": { "terms" : { "field": "Meta.GeoInfo.Country.keyword","missing_bucket": true } } }
]
}
}
}
}
size:0 -> makes the output show the aggregated buckets only instead of the whole documents
Tuesday, November 19, 2019
Sunday, November 3, 2019
Fixing date field formats to upgrade elastic to version 7
Here is what did, that eventually worked:
- The only way I found to EDIT the field format was by creating a new (empty) index, by specifying its mapping. The date fields I replaced (had my json in a text editor and did a "replace all" on each different format to a elastic-7-complying one. In my case, most of my fields were "yyyy/MM/dd HH:mm:ss||yyyy/MM/dd||epoch_millis", and I changed them to "8yyyy/MM/dd HH:mm:ss||8yyyy/MM/dd".
- Then I issued a _reindex, meaning I copied the contents of each index I had to fix to its corresponding new empty index I created, in the step above, to hold its data, now in a compatible format
- At the end of the reindex (do not worry about the "backend connection closed" message, the copy keeps running, check the "Reload Indices" in Index Management), I added an alias to the new index so that new documents being added to the original one are now inserted in the new one (using the _alias api)
- If you want the indexes to remain with their original names at the end, you can then copy once again the indexes to a new one, using the original name this time. Be aware that before doing that you must remove the alias you added in step (3), other wise the engine thinks the index already exists (because references to the alias translate into references to the new index).
CAUTION: My dashboards stopped working. I have an open ticket with Elastic's support at the moment waiting for instructions.
At this stage, after doing the above to all indexes that had warnings on date formats, you should reach the stage where you have no warnings left, and are ready for the upgrade.
At this stage, after doing the above to all indexes that had warnings on date formats, you should reach the stage where you have no warnings left, and are ready for the upgrade.
Tuesday, September 24, 2019
Get Enum Attribute Value in C#
public static string GetEnumAttributeValue(Enum enumValue, Type attributeType, string attributePropertyName)
{
/*
* Extracts a given attribute value from an enum:
*
* Ex:
* public enum X
* {
[MyAttribute(myProp = "aaaa")]
* x1,
* x2,
* [Description("desc")]
* x3
* }
*
* Usage:
* GetEnumAttribute(X.x1, typeof(MyAttribute), "myProp") returns "aaaa"
* GetEnumAttribute(X.x2, typeof(MyAttribute), "myProp") returns string.Empty
* GetEnumAttribute(X.x3, typeof(DescriptionAttribute), "Description") returns "desc"
*/
var attributeObj = enumValue.GetType()?.GetMember(enumValue.ToString())?.FirstOrDefault()?.GetCustomAttributes(attributeType, false)?.FirstOrDefault();
if (attributeObj == null)
return string.Empty;
else
{
try
{
var attributeCastedObj = Convert.ChangeType(attributeObj, attributeType);
var attributePropertyValue = attributeType.GetProperty(attributePropertyName)?.GetValue(attributeCastedObj);
return attributePropertyValue?.ToString() ?? string.Empty;
}
catch (Exception ex)
{
return string.Empty;
}
}
}
{
/*
* Extracts a given attribute value from an enum:
*
* Ex:
* public enum X
* {
[MyAttribute(myProp = "aaaa")]
* x1,
* x2,
* [Description("desc")]
* x3
* }
*
* Usage:
* GetEnumAttribute(X.x1, typeof(MyAttribute), "myProp") returns "aaaa"
* GetEnumAttribute(X.x2, typeof(MyAttribute), "myProp") returns string.Empty
* GetEnumAttribute(X.x3, typeof(DescriptionAttribute), "Description") returns "desc"
*/
var attributeObj = enumValue.GetType()?.GetMember(enumValue.ToString())?.FirstOrDefault()?.GetCustomAttributes(attributeType, false)?.FirstOrDefault();
if (attributeObj == null)
return string.Empty;
else
{
try
{
var attributeCastedObj = Convert.ChangeType(attributeObj, attributeType);
var attributePropertyValue = attributeType.GetProperty(attributePropertyName)?.GetValue(attributeCastedObj);
return attributePropertyValue?.ToString() ?? string.Empty;
}
catch (Exception ex)
{
return string.Empty;
}
}
}
Monday, August 26, 2019
Monday, August 12, 2019
Monday, August 5, 2019
Wednesday, June 26, 2019
Get Date Out of an Elastic Timestamp
I am not sure, but I think the answer to the question on how to get a date out of an elastic timestamp,
can be using the Current Epoch Timestamp To Date
converter in this site.
can be using the Current Epoch Timestamp To Date
converter in this site.
Monday, June 24, 2019
Print call stack in javascript
From https://til.hashrocket.com/posts/478143b559-print-call-stack-on-javascript
Print call stack on Javascript If you want to print the javascript **call stack** you can use: ```javascript console.log(new Error().stack); ``` Here it is an **example**: ```javascript function firstFunction() { secondFunction(); } function secondFunction() { thridFunction(); } function thridFunction() { console.log(new Error().stack); } firstFunction(); //=> Error // at thridFunction (<anonymous>:2:17) // at secondFunction (<anonymous>:5:5) // at firstFunction (<anonymous>:8:5) // at <anonymous>:10:1 ``` h/t @rondale_sc viniciusnegrisolo June 10, 2016
Tuesday, June 11, 2019
Increasing maximum allowed post body content size in .NET Web Api
This SO answer did the job.
I used int.MaxValue instead.
Sunday, May 19, 2019
Turning off .net core Transfer-Encoding Chuked automatic header
var objectContent = new ObjectContent<Dictionary<string, DataTable>>(dataTablesDic, new JsonMediaTypeFormatter(), "application/json");
var json = Newtonsoft.Json.JsonConvert.SerializeObject(dataTablesDic);
//setting request's content ContentLength's header was the only way I found to turn off .net core automatic Transfer-Encoding=Chunked setting, which was resulting in web api post object binding failure
objectContent.Headers.ContentLength = Encoding.UTF8.GetByteCount(json);
var result = httpClient.PostAsync($"http://localhost:65000/File/GetExcel?bucketDestinationPath={fileName}&S3bucketName=myBuketName", objectContent)?.Result;
var json = Newtonsoft.Json.JsonConvert.SerializeObject(dataTablesDic);
//setting request's content ContentLength's header was the only way I found to turn off .net core automatic Transfer-Encoding=Chunked setting, which was resulting in web api post object binding failure
objectContent.Headers.ContentLength = Encoding.UTF8.GetByteCount(json);
var result = httpClient.PostAsync($"http://localhost:65000/File/GetExcel?bucketDestinationPath={fileName}&S3bucketName=myBuketName", objectContent)?.Result;
Wednesday, April 17, 2019
Disable automatic assembly redirect
https://docs.microsoft.com/en-us/dotnet/framework/configure-apps/how-to-enable-and-disable-automatic-binding-redirection
Did not read the following, but may be of help:
Did not read the following, but may be of help:
Tuesday, March 26, 2019
Breakpoints in .net core library will not be hit when debugging consuming WinForms app
https://stackoverflow.com/q/55359599/1219280
Check the project's Debug information property found here: Properties > Build > Advanced (button at bottom) > Debugging information
Check the project's Debug information property found here: Properties > Build > Advanced (button at bottom) > Debugging information
Retrieving Jenkins Credentials passwords using Jenkins Script Console
https://github.com/tkrzeminski/jenkins-groovy-scripts/blob/master/show-all-credentials.groovy
import jenkins.model.*
import com.cloudbees.plugins.credentials.* import com.cloudbees.plugins.credentials.impl.* import com.cloudbees.plugins.credentials.domains.* import com.cloudbees.jenkins.plugins.sshcredentials.impl.BasicSSHUserPrivateKey import com.cloudbees.jenkins.plugins.awscredentials.AWSCredentialsImpl import org.jenkinsci.plugins.plaincredentials.StringCredentials import org.jenkinsci.plugins.plaincredentials.impl.FileCredentialsImpl def showRow = { credentialType, secretId, username = null, password = null, description = null - > println("${credentialType} : ".padLeft(20) + secretId ? .padRight(38) + " | " + username ? .padRight(20) + " | " + password ? .padRight(40) + " | " + description) } // set Credentials domain name (null means is it global) domainName = null credentialsStore = Jenkins.instance.getExtensionList('com.cloudbees.plugins.credentials.SystemCredentialsProvider')[0] ? .getStore() domain = new Domain(domainName, null, Collections. < DomainSpecification > emptyList()) credentialsStore ? .getCredentials(domain).each { if (it instanceof UsernamePasswordCredentialsImpl) showRow("user/password", it.id, it.username, it.password ? .getPlainText(), it.description) else if (it instanceof BasicSSHUserPrivateKey) showRow("ssh priv key", it.id, it.passphrase ? .getPlainText(), it.privateKeySource ? .getPrivateKey(), it.description) else if (it instanceof AWSCredentialsImpl) showRow("aws", it.id, it.accessKey, it.secretKey ? .getPlainText(), it.description) else if (it instanceof StringCredentials) showRow("secret text", it.id, it.secret ? .getPlainText(), '', it.description) else if (it instanceof FileCredentialsImpl) showRow("secret file", it.id, it.content ? .text, '', it.description) else showRow("something else", it.id, '', '', '') } return
Tuesday, March 12, 2019
Updating multiple fields, one of them conditionally in SQL
UPDATE
table
SET
f1 = 27521,
f2 = CASE
WHEN f2 = 21 AND actionType = 12 THEN
27521
ELSE
f2
END
WHERE
f1 = 21
table
SET
f1 = 27521,
f2 = CASE
WHEN f2 = 21 AND actionType = 12 THEN
27521
ELSE
f2
END
WHERE
f1 = 21
Sunday, March 3, 2019
Enabling mysql.general_log
SET global general_log = 1;
SET global log_output = 'table';
Taken from here
Wednesday, February 13, 2019
Looking for (and killing) locks in mySQL
Taken from here.
1) List all your processes with
SHOW FULL PROCESSLIST
2) Look at the "State" column, it will mention a lock if existent
3) Kill the process you want by running
KILL [process_id_taken_from_process_list]
1) List all your processes with
SHOW FULL PROCESSLIST
2) Look at the "State" column, it will mention a lock if existent
3) Kill the process you want by running
KILL [process_id_taken_from_process_list]
Sunday, February 10, 2019
Javascript Array Distinct functionality
https://codeburst.io/javascript-array-distinct-5edc93501dc4
Tuesday, February 5, 2019
Translating Set Operations into SQL Joins
Thanks to a colleague from work for sharing this.
The last one is was not familiar to me.
Good to know.
The last one is was not familiar to me.
Good to know.
Subscribe to:
Posts (Atom)