Skip to content

Instantly share code, notes, and snippets.

Avatar

Martin Carel cawel

View GitHub Profile
@cawel
cawel / javascript-interview-question-8.js
Last active Mar 14, 2018
JavaScript Interview Question
View javascript-interview-question-8.js
var person = {
_name: 'John Doe',
getSecretIdentity: function (){
return this._name;
}
};
var stoleSecretIdentity = person.getSecretIdentity;
console.log(stoleSecretIdentity());
@cawel
cawel / javascript-interview-question-7.js
Created Mar 13, 2018
JavaScript Interview Question
View javascript-interview-question-7.js
var myObject = {
foo: "bar",
func: function() {
var self = this;
console.log("outer func: this.foo = " + this.foo);
console.log("outer func: self.foo = " + self.foo);
(function() {
console.log("inner func: this.foo = " + this.foo);
console.log("inner func: self.foo = " + self.foo);
}());
@cawel
cawel / javascript-interview-question-3.js
Created Mar 12, 2018
JavaScript Interview Question
View javascript-interview-question-3.js
var age = 20
(function () {
console.log("Original age is " + age)
var age = 30
console.log("The new age is " + age)
})()
@cawel
cawel / javascript-interview-question-6.js
Created Mar 12, 2018
JavaScript Interview Question
View javascript-interview-question-6.js
var foo = function(){
// Some code
};
function bar(){
// Some code
};
@cawel
cawel / javascript-interview-question-5.js
Last active Mar 14, 2018
JavaScript Interview Question
View javascript-interview-question-5.js
var a = [0,1,2,3,4,5,6,7,8,9]
a.slice()
a.splice()
a.concat([24])
a.reverse()
@cawel
cawel / javascript-interview-question-4.js
Created Mar 12, 2018
javascript-interview-question-4.js
View javascript-interview-question-4.js
const operations = []
for (var i = 0; i < 5; i++) {
operations.push(() => {
console.log(i)
})
}
for (const operation of operations) {
operation()
@cawel
cawel / javascript-interview-question-1.js
Last active Mar 12, 2018
javascript-interview-question-1.js
View javascript-interview-question-1.js
const multiply = x => y => z => x * y * z
console.log( multiply(2)(3)(4) )
View gist:3fa4bb21572d36a72a24
#!/usr/bin/env ruby
require 'socket'
client = TCPSocket.open("127.0.0.1", 2222) {|s| s.send("hello", 0) }
View gist:0e0455cfed318ae7007e
#!/usr/bin/env ruby
require 'open-uri'
open('http://www.imdb.com/title/tt0421054/') do |f|
f.read.match(/User Rating:<\/b>\s*([\d\.]+\/[\d\.]+)<\/b>/)
puts $1
end
View gist:e046d6a5163addc99a0d
class Array
def my_map
result = []
each do |e|
result << (yield e)
end
result
end
end
You can’t perform that action at this time.