Skip to content

Instantly share code, notes, and snippets.

View vojto's full-sized avatar
🎯
Focusing

Vojtech Rinik vojto

🎯
Focusing
  • Kosice, Slovakia
  • 15:31 (UTC -12:00)
  • X @_vojto
View GitHub Profile
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>DVTConsoleDebuggerInputTextColor</key>
<string>0.7653 0.699234 0.758969 1</string>
<key>DVTConsoleDebuggerInputTextFont</key>
<string>Menlo-Bold - 12.0</string>
<key>DVTConsoleDebuggerOutputTextColor</key>
<string>0.6431 0.5881 0.637824 1</string>
@vojto
vojto / async_javascript.markdown
Created August 13, 2011 15:27
Improve your asynchronous JavaScript code

Improve your asynchronous JavaScript code

While trying to improve my Node.js code by studying code of others, I realized that Pow is written in JavaScript. Even better, CoffeeScript.

And of course, nothing is easier to read than annotated source code generated by Docco.

Let me show you a couple of tricks I learned from their code.

CoffeeScript (de)structuring

- (void)keyDown:(NSEvent *)theEvent {
unsigned short key = [theEvent keyCode];
BOOL up;
if (key == 38) up = NO;
else if (key == 40) up = YES;
else return [super keyDown:theEvent];
BOOL down = !up;
NSInteger index = [self selectedRow];
fs = require 'fs'
coffeescript = require 'coffee-script'
optionsString = fs.readFileSync("config.coffee", "utf-8")
options = coffeescript.eval(optionsString)
@layout = new Layout(el: @el)
@courses = new Courses (layout: @layout, app: @)
@login = new Login (layout: @layout, app: @)
@account = new Account (layout: @layout, app: @)
@messages = new Messages(layout: @layout, app: @)
@sidebar = new Sidebar (layout: @layout, app: @)
@vojto
vojto / cv3.hs
Created March 6, 2012 10:24
Cvicenie 3
-- # --------------------------------------------------------------------------
-- # Enumeracne typy
-- # --------------------------------------------------------------------------
data Eval = A|B|C|D|E|FX deriving(Show, Eq, Ord, Enum)
-- # --------------------------------------------------------------------------
-- # Dni
-- # --------------------------------------------------------------------------
mensie xs = [x | x <- xs, x < 10]
quicksort (x:xs) = quicksort [y | y <- xs, y <= x] ++ [x] ++
quicksort [y | y <- xs, y > x]
quicksort _ = []
-- # Praca so zoznamom
-- foldl - injecct
-- foldl (+) 0 [1, 2, 3]

iCubes Git Tricks

Colors

Add this to your ~/.gitconfig

[color]
  branch = auto
  diff = auto

status = auto

@vojto
vojto / 01_auth.js
Created April 8, 2012 09:48
JavaScript vs. CoffeeScript vs. IcedCoffeeScript
// JavaScript
auth: function(username, password, callback) {
var self = this;
var hash = this._encodePassword(password);
this.model.find({name: username, encoded_password: hash}, function(err, docs) {
if (docs.length == 0) return callback(false);
var user = docs[0];
self._generateToken(user, function(token) {
callback(user, token);
# __
# ()'`;
# /\|`
# / |
# (/_)_|_
#
class Server
# -^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-
# Lifecycle