@kangax created a new interesting quiz, this time devoted to ES6 (aka ES2015). I found this quiz very interesting and quite hard (made myself 3 mistakes on first pass).
Here we go with the explanations:
(function(x, f = () => x) {
/** | |
* Title | |
* | |
* @author | |
* @version 1.0 | |
* @description | |
* @uses | |
* @history | |
* yyyy-mm-dd : | |
*/ |
String key = 'hgdhdhhdjfh12ehsn'; | |
String secret = 'DNf32sdsj747dhkjd8893jjjdjds7jjk'; | |
//Generating current Unix timestamp (in seconds) | |
String getTime = string.valueOf(Datetime.Now().getTime()/1000); | |
String requestInput = key + secret + getTime; | |
Blob requestBlob = Blob.valueOf(requestInput); | |
Blob hash = Crypto.generateDigest('MD5', requestBlob); | |
//Need to convert into hex to generate the equivalent of md5(string) method of PHP. |
/* | |
* Splits array into subarrays. | |
* count parameter indicates that how many item per subarray contains. | |
* Example usage: splitIntoSubArray([1,2,3,4,5], 2) -> [[1, 2], [3, 4], [5]] | |
*/ | |
function splitIntoSubArray(arr, count) { | |
var newArray = []; | |
while (arr.length > 0) { | |
newArray.push(arr.splice(0, count)); | |
} |
@kangax created a new interesting quiz, this time devoted to ES6 (aka ES2015). I found this quiz very interesting and quite hard (made myself 3 mistakes on first pass).
Here we go with the explanations:
(function(x, f = () => x) {
public static String getAllQuery(String query) { | |
String result = ''; | |
String regex = '^select\\s+\\*\\s*(?:,\\s*[^\\s]+\\s*)*\\s+from\\s+([^\\s]+)(.*)$'; | |
Matcher m = Pattern.compile(regex).matcher(query.toLowerCase()); | |
if(m.matches()) { | |
String sObjectName = m.group(1); | |
Schema.SObjectType targetType = Schema.getGlobalDescribe().get(sObjectName); | |
Map<String, Schema.SObjectField> fieldMap = targetType.getDescribe().fields.getMap(); |
<html> | |
<body> | |
<script type="text/javascript" src="//mozilla.github.io/pdf.js/build/pdf.js"></script> | |
<script type="text/javascript"> | |
var url = "https://docs.google.com/document/export?format=pdf&id=1ML11ZyyMpnAr6clIAwWrXD53pQgNR-DppMYwt9XvE6s&token=AC4w5Vg7fSWH1Hq0SgNckx4YCvnGPaScyw%3A1423618416864"; | |
var pages = [], heights = [], width = 0, height = 0, currentPage = 1; | |
var scale = 1.5; | |
function draw() { |
/** | |
* Copyright (c), Andrew Fawcett | |
* All rights reserved. | |
* | |
* Redistribution and use in source and binary forms, with or without modification, | |
* are permitted provided that the following conditions are met: | |
* | |
* - Redistributions of source code must retain the above copyright notice, | |
* this list of conditions and the following disclaimer. | |
* - Redistributions in binary form must reproduce the above copyright notice, |
IE9, IE10, and IE11 don't properly scale SVG files added with img
tags when viewBox
, width
and height
attributes are specified. View this codepen on the different browsers.
Image heights will not scale when the images are inside containers narrower than image widths. This can be resolved in 2 ways.
As per this answer on Stackoverflow, the issue can be resolved by removing just the width
and height
attributes.
import java.util.ArrayList; | |
import java.util.Iterator; | |
import java.util.List; | |
import java.util.concurrent.Callable; | |
import java.util.concurrent.ExecutorService; | |
import java.util.concurrent.Future; | |
import java.util.concurrent.LinkedBlockingQueue; | |
import java.util.concurrent.ThreadPoolExecutor; | |
import java.util.concurrent.TimeUnit; |