Skip to content

Instantly share code, notes, and snippets.

View yefremov's full-sized avatar

Jeff yefremov

  • Riga, Latvia
View GitHub Profile
@yefremov
yefremov / getStyles.js
Created February 18, 2017 18:01
Cross-browser method to get all CSS properties after all active sheets were applied and calculated
var getStyles = window.getComputedStyle
? function (node) { return window.getComputedStyle(node, null) };
: function (node) { return node.currentStyle };
@yefremov
yefremov / hmss.js
Created February 15, 2017 23:04
Get hours, minutes and seconds from milliseconds.
function hmss(ms) {
var result = [];
result[0] = ((ms % 216e6) / 36e5) | 0;
result[1] = ((ms % 36e5) / 6e4) | 0;
result[2] = ((ms % 6e4) / 1e3) | 0;
result[3] = (ms % 1e3) | 0;
return result;
}
@yefremov
yefremov / explode-string.ml
Last active February 8, 2017 23:13
Implements string explode in OCaml
(* Explode string *)
let explode str =
let rec exp i acc =
if i < 0 then acc
else exp (i - 1) (str.[i] :: acc) in
exp (String.length str - 1) []
(* # explode "foo bar baz ";;
* - : char list = ['f'; 'o'; 'o'; ' '; 'b'; 'a'; 'r'; ' '; 'b'; 'a'; 'z'; ' ']
@yefremov
yefremov / jsdom-issue-1728.js
Last active February 6, 2017 18:59
With the release 9.10.0 element.offsetWidth returns `undefined`
// https://github.com/tmpvar/jsdom/issues/1728
// npm i
// node jsdom-issue-1728.js
var jsdom = require("jsdom").jsdom;
var window = jsdom().defaultView;
var elementA = window.document.createElement("div");
var elementB = window.document.createElement("div");
function rotate(array, n) {
while(n--) {
var index = -1;
var length = array.length;
var temp = array.slice();
while (++index < length) {
array[(index + 1) % length] = temp[index];
}
}
(*
Task
Given the starter code, complete the Fibonacci function to return the term.
We start counting from Fibonacci(1) = 0. This might differ from some other notations that treats Fibonacci(0) = 0.
*)
open Scanf;;
let n = bscanf Scanning.stdin " %d" (fun x -> x);;
(*
Task
Given the starter code, you need to complete a function body that returns the GCD of two given integers and .
The task of reading in input and printing the output will be handled by us.
Programming Language Support
At this point of time, we have a template for Scala. This means that we provide the code required to accept
the input and display the output.
*)
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
int n1;
/**
* Check whether string `s2` is a rotated version of `s1`.
* http://stackoverflow.com/questions/2553522/interview-question-check-if-one-string-is-a-rotation-of-other-string
*
* Example:
*
* is_rotated("tackoverflows", "ackoverflowst");
* // => true
*/
var N = parseInt(readline());
var T = {};
for (var i = 0; i < N; i++) {
var t = readline();
T[parseInt(t.replace(/:/g, ''), 10)] = t;
}
print(T[Object.keys(T).sort((a, b) => a - b)[0]]);