List of helpful shortcuts for faster coding
If you have any other helpful shortcuts, feel free to add in the comments of this gist :)
/* | |
Write a program that prints the numbers from 1 to 100. But for multiples | |
of three print “Fizz” instead of the number and for the multiples of five print “Buzz”. | |
For numbers which are multiples of both three and five print “FizzBuzz”. | |
*/ |
/* | |
Create a function that will allow you to pass in a string, with the ability to add to this with more function calls. | |
When it is finally passed an empty argument returns the full concatenated string of all arguments passed previously. | |
// For example: mergeWords("Hello")("World!")("how")("are")("you?")(); | |
// This will return the following: "Hello World! how are you?" | |
*/ |
/* | |
Given an array, rotate the array to the right by k steps, where k is non-negative. | |
Example 1: | |
Input: nums = [1,2,3,4,5,6,7], k = 3 | |
Output: [5,6,7,1,2,3,4] | |
Explanation: | |
rotate 1 steps to the right: [7,1,2,3,4,5,6] | |
rotate 2 steps to the right: [6,7,1,2,3,4,5] |
/** | |
* @param {number[]} nums | |
* @param {number} k | |
* @return {void} Do not return anything, modify nums in-place instead. | |
*/ | |
// using unshift and pop method (Good for first run) | |
var rotateByUnshift = function(nums, k) { | |
k = k > nums.length ? k - nums.length : k; | |
for(var i=0;i<k;i++){ | |
nums.unshift(nums.pop()); |
// Create a function that will allow you to pass in a string, with the ability to add to this with more function calls. When it is finally passed an empty argument return the full concatinated string of all arguments pased previously. | |
// For example: mergeWords("Hello")("World!")("how")("are")("you?")(); | |
// This will return the following: "Hello World! how are you?" | |
// Solution 1 | |
function mergeWords(string) { | |
return function(nextString) { | |
if (nextString === undefined) { | |
return string; | |
} else { |
{"contents":{"editor":{"formatOnSave":true}},"overrides":[],"keys":["editor.formatOnSave"]} |
SELECT DATE_TRUNC('day', time) AS __timestamp, | |
fill_level AS fill_level, | |
sensor_id AS sensor_id, | |
AVG(sensor_id) AS "AVG(sensor_id)" | |
FROM demo.pg_fill_measurements | |
GROUP BY fill_level, | |
sensor_id, | |
DATE_TRUNC('day', time) | |
ORDER BY "AVG(sensor_id)" DESC | |
LIMIT 10000; |
SELECT DATE_TRUNC('day', time) AS __timestamp, | |
fill_level AS fill_level, | |
AVG(sensor_id) AS "AVG(sensor_id)" | |
FROM demo.fill_measurements | |
JOIN | |
(SELECT fill_level AS fill_level__, | |
AVG(sensor_id) AS mme_inner__ | |
FROM demo.fill_measurements | |
GROUP BY fill_level | |
ORDER BY mme_inner__ DESC |
Limit (cost=4895237.19..4897350.43 rows=10000 width=48) (actual time=16791.597..23517.086 rows=1000 loops=1) | |
-> Finalize GroupAggregate (cost=4895237.19..5922277.78 rows=4860039 width=48) (actual time=16791.595..23516.865 rows=1000 loops=1) | |
Group Key: sensor_id, (time_bucket('1 day'::interval, "time")) | |
-> Gather Merge (cost=4895237.19..5800776.80 rows=4860039 width=48) (actual time=16790.127..23513.261 rows=2000 loops=1) | |
Workers Planned: 1 | |
Workers Launched: 1 | |
-> Partial GroupAggregate (cost=4894237.18..5253022.41 rows=4860039 width=48) (actual time=16774.942..23280.625 rows=1000 loops=2) | |
Group Key: sensor_id, (time_bucket('1 day'::interval, "time")) | |
-> Sort (cost=4894237.18..4965708.34 rows=28588464 width=22) (actual time=16763.580..19623.318 rows=24300250 loops=2) | |
Sort Key: sensor_id DESC, (time_bucket('1 day'::interval, "time")) |