This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/sh | |
| ADD="sudo route add -net" | |
| DEL="sudo route delete -net" | |
| # Interfaces -> gateway | |
| WIFI=192.168.2.1 | |
| THUN=192.168.1.1 | |
| # Internal networks |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def fizzbuzz(x) | |
| result = "#{'Fizz' if x % 3 == 0}#{'Buzz' if x % 5 == 0}" | |
| result.empty? ? "#{x}" : result | |
| end | |
| def print_range(x) | |
| (1..x).each { |el| puts fizzbuzz(el) } | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Struct to Hash | |
| class Struct | |
| def to_hash | |
| Hash[*members.map(&:to_s).zip(values).flatten] | |
| end | |
| end | |
| # Hash to Struct | |
| class Hash | |
| def to_struct(name) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import "fmt" | |
| func fib(n int) (r int) { | |
| switch n { | |
| case 0: | |
| r = 0 | |
| case 1: | |
| r = 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @DateToEpoch = (date) -> | |
| parseInt(date.getTime()/1000) | |
| @DateFromEpoch = (epochTime) -> | |
| tmp = new Date 0 | |
| tmp.setUTCSeconds epochTime | |
| @DateToStr = (date) -> | |
| y = "#{date.getFullYear()}" | |
| m = "#{date.getMonth() + 1}" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ESC="\033" # This is the escape sequence | |
| NO_COLOR="$ESC[0m" | |
| IRED="$ESC[1;31m" # ANSI color code for intense/bold red | |
| IGRN="$ESC[1;32m" # ANSI color code for intense/bold green | |
| # From http://railstips.org/blog/archives/2009/02/02/bedazzle-your-bash-prompt-with-git-info/ | |
| # I had to change 'git-symbolic-ref' to 'git symbolic-ref' | |
| function parse_git_branch { | |
| ref=$(git symbolic-ref HEAD 2> /dev/null) || return | |
| echo " ["${ref#refs/heads/}"]" # I wanted my branch wrapped in [], use () or <> or whatever |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module PrintDuration | |
| def print_duration(name) | |
| start = Time.now | |
| result = yield | |
| total = (Time.now - start) * 1000 | |
| puts "#{name}: #{total.to_i}ms" | |
| result | |
| end | |
| alias_method :some_method_orig, :some_method |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'redis' | |
| require 'em-websocket' | |
| SOCKETS = [] | |
| @redis = Redis.new(:host => '127.0.0.1', :post => 6379) | |
| # Creating a thread for the EM event loop | |
| Thread.new do | |
| EventMachine.run do | |
| # Creates a websocket listener |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| this.xmpp ?= {} | |
| class XmppClient | |
| constructor: -> | |
| @interlocutors = [] | |
| @currentUserId = window.currentUserId | |
| # @dispatcher = new WebSocketRails "xmpp.dev.improva.com/websocket" | |
| # @dispatcher = new WebSocketRails "localhost:3000/websocket" | |
| @dispatcher = new WebSocketRails window.websocketPath | |
| @channel = @dispatcher.subscribe "messages" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'xmpp4r' | |
| require 'xmpp4r/roster' | |
| module XmppExtension | |
| # class Jabber::JID | |
| # # generate node@domain | |
| # def to_short_s | |
| # s = [] | |
| # s << "#@node@" if @node |