Skip to content

Instantly share code, notes, and snippets.

@Struki84
Last active March 21, 2018 12:30
Show Gist options
  • Save Struki84/59568b74531684e74aebe5d6f1a32dc7 to your computer and use it in GitHub Desktop.
Save Struki84/59568b74531684e74aebe5d6f1a32dc7 to your computer and use it in GitHub Desktop.
Worm Test Solutions
Node.js - Questions
+ Q: What is an error-first callback?
A: I have used this style convention, never knew it was a "thing", I googled it :). It is an accepted style of formatting
your callback data in a way to separate your err response from your data response, and return error as the first argument,
in a way always anticipating the error. It is more of a preference than an actual design pattern since a lot of programmers
set an error check condition before running any other operations on executing callback, eg:
var callback = function(error, data) {
if (error) {
//you have an error do something
}
else {
//no errors no do something with $data
}
}
+ Q: How can you avoid callback hells?
A: The fastest answer would be, use Design Patterns, group code in Modules, use Promises. The long answer... Callbacks are
JS way of handling asynchronous operations in the code. I didn't understand callbacks in JS until I started using swift.
The reason for that was that JS is implicit type language while swift is an explicit type (well optional, but its objectiveC
in the background which is explicit typed language). So when I started to learn about "callbacks" in swift, the way you
have to declare them is far more clear in swift witch helped me realise those are actual closures and that callbacks are
nothing but some implicitly defined closures. It was one of those AHA! moments for me, and after that I was much craftier
in avoiding call back hells. The way I did that is by applying design patterns from swift in JS. In the real world, I think
AngularJS is a good example of how the application of Desing Patterns, and modulation can work around the callbacks.
+ Q: What are Promises?
A: Well promises, are as mentioned above, designed as a way of solving the call back problem. Or more specifically, it is
extended solution for handling asynchronous requests, but instead of resolving the request/operation in callback you can
store the result in a variable/object, and check its status then resolve them within code in a way that seems procedural and
synchronous. You check the request by checking the status:
+ Pending
+ Rejected
+ Fulfiled
//so instead something like:
function SayHello(callback){
callback(error, hello)
}
SayHello(function(err, hello){
if (err){
//error
}
else {
console.log(hello)
}
})
//you get something like
var promise = SayHello()
//some code
promise.then(function(hello){
console.log(hello)
})
.catch(function(err){
console.log(err)
})
+ Q: What tools can be used to assure consistent style? Why is it important?
A: I have never worked in a team that cared enough about standardisation to use styling tools, I did most of it manually
for myself. But I'm aware of the libs that you can include and use. I have been looking for like minded people on this
matter(Tom is one :)), as en engineer, I'm aware of the benefits of standardized process. To keep it short, it's important
because standardization means more effectiveness and more effectiveness means more results with less energy consumed, which
in simple terms means more money earned since you reduced your costs :)
+ Q: What's your favorite HTTP framework and why?
A: I use Ruby, Sinatra Fw, in general I always prefer micorframeworks over large rigid fw like Rails. But It has its plus
and cons, I use it primarily because It is more flexible and has a small footprint, file structure is under manual control
(as opposed to rail). At the same time it is easily expandable with Sinatra modules, since its a namespace framework you
can also expand it by yourself with custom modules with out touching the core or needing to do and "installation" of the
module in the fw. The reason I primarily use it is because I do a lot of prototyping, and I can set up just what I need in
Sinatra very fast from scratch, without any cumbersome processes like installing an entire fw. I'll attach some links at
the end of the file so you can take a look at some server side code I've been doing the last year
+ Q: How can you secure your HTTP cookies against XSS attacks?
A: Honestly security is my least skilled area, I'm more of architecture and process guy, so I googled this. Primary point
of defense, as I can gather,is encrypting your cookie in a browser, and sending cookies over TLS to protect them in transit. Also, there are a bunch of attributes you can set to uniquely identify your cookie and tell the browser what to expect
iOS - Questions
+ Q: Documentation outlines that AwesomePod supports Swift 3.2 with AwesomePod 6.2, however you keep getting AwesomePod 4.0
after a pod install. What are your options? (You have to use cocoa pods)
A: You can do a few things, apart from the basics like checking the cocoapods itself, upgrading, updating, checking ruby
env and stuff like that, more likely is you have to,
+ point to specific Cocoapod version smth like: pod 'AwesomePod', '~> 6.2'
+ if the pod allows it find the specific github realse, like:
pod 'AwesomePod', :git => 'https://github.com/AwesomePod/path/to/specific/realese'
+ download the source code and add it manually as fw to the workspace
+ include it it as git submodule
+ copy and manually add the code to your project just by Add Files
+ solve the problem, write the damn lib your self :)
+ Q: Write a simple extension so we can make any view in the project to hide itself in x seconds just by calling it’s
“hideWithAnimation” method.
extension UIView {
func hideWithAnimation(duration: TimeInterval) {
UIView.animate(withDuration: duration) {
self.alpha = 0
}
}
}
+ Q: You got an object called mercedes which is an optional. What’s the correct way to check if mercedes exists and to access it’s seats: [String]? property in a single line
A: I would really like to have an object named Mercedes ^_^
guard let mercedesSeats = mercedes?.seats else {
return
}
if let numberOfSeats = mercedes?.seats {
print(numberOfSeats)
}
+ Q: Create a circular red button and make it appear in (20,100, 50, 50) of your view using PureLayout.
A: I have never used it, just googled it, docs aren't that much helpful at a glance, seems an overkill to me, I would need
some more time to dwell into the docs and the pod. Personally, I've given up on coding the layouts, I've become highly
proficient in using interface builder, and with the @Designable classes in swift I can update the interface with code
really fast. Switching to IB for Layout Building halfed my dev time in general.
Some of my code:
Ruby(Sinatra) web app
+ live: dev.eventomate.me
+ source: https://github.com/Sintezis/eventomate.me
Ruby(Sinatra) api sever
+ source: https://github.com/Sintezis/fooc.server
Swift iOS app:
+ source: https://github.com/Sintezis/Fooc
Swift Test I did yesterday api driven weather app woth out 3rd part libs:
+ source: https://github.com/Struki84/TandemTest
Check it out! :)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment