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
class PersistentHttpClient | |
def self.get(url) | |
uri = url.is_a?(URI) ? url : URI(url) | |
connection_manager.get_connection(uri) | |
end | |
def self.connection_manager | |
Thread.current[:persistent_http_connection_manager] ||= new_manager | |
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
def get_helper_modules(subtree = []) | |
helper_directory = Rails.root.join('app').join('helpers') | |
subtree.each do |folder| | |
helper_directory = helper_directory.join(folder) | |
end | |
entries = Dir.entries(helper_directory) - %w(. ..) | |
files = entries.select { |e| e.include?('.rb') } | |
modules = files.map do |file| | |
module_name = subtree.map(&:camelcase).join('::') | |
if module_name.present? |
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
return { | |
type: actionType, | |
channel: channelName, | |
event: eventName, | |
data: data | |
}; |
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
class ApplicationController < ActionController::Base | |
before_filter :set_page_title | |
CONTROLLER_TITLES = Hash.new | |
# for setting page titles for the whole controller | |
def self.page_title title | |
CONTROLLER_TITLES[self.name] = title | |
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
$.ajax({ | |
dataType: "json", | |
url: "/stuff/" + id + "/do_something", | |
data: {x: x, y: y} | |
}).done(function(response){ | |
window.alert("Yay!"); | |
}).fail(function(error){ | |
// even if no message is provided we should tell a user that something went wrong | |
errorMessage = (error.responseJSON && error.responseJSON.message) || "Some error occurred!" | |
window.alert(errorMessage); |
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
var $injector = angular.element(document).injector(); // first we get the injector our app uses | |
$injector.invoke(function($rootScope, $compile) { // you inject anything here in params | |
var element = angular.element('#selector'); // get the element we want to parse | |
// following hack isn't always neccessary, but I use to prevent double parsing if the same HTML is generated statically and dynamically | |
if (element.attr('class') && element.attr('class').indexOf("ng-scope")!=-1){ | |
return; | |
} | |
var compiled = $compile(element)($rootScope); // finally, we compile the element against root scope | |
compiled.scope().$apply(); // ... and we tell Angular that we made changes outside of its 'world' | |
}); |
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 'awesome_print' | |
folder = "/media/media_nas_drive/Train/Video/Biology/Consumer Neuroscience/" | |
folder_for_cd = folder.gsub(' ', '\ ') | |
files = Dir[folder+'*.mp4'].map{|f| f.gsub(folder, '').gsub('.mp4', '')} | |
files.each_with_index do |f, i| | |
ap "!!!!!!!!!" | |
ap "#{i+1}/#{files.length}" | |
ap "!!!!!!!!!" | |
system "cd #{folder_for_cd} && ffmpeg -i \"#{f}.mp4\" -f srt -i \"#{f}.srt\" -c:v copy -c:a copy \ | |
-c:s mov_text \"new_video/#{f}.mp4\"" |
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
'use strict'; | |
angular.module('chatApp') | |
.controller 'ChatCtrl', ($scope, Socket)-> | |
socket = Socket($scope) | |
socket.emit 'subscribe', {} | |
$scope.messages = [ ] | |
socket.on 'message_history', (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
auth = (role_middleware_hash)-> | |
return (req, res, next)-> | |
# transform to [{role: function}, {another_role: true}] format: | |
role_middleware_array = for key, value of role_middleware_hash then obj={}; obj[key]=value; obj | |
if not req.user? then res.send(403); return; # no user == no access | |
nextFn = (allowed)-> | |
if allowed is true # previous call allowed access | |
next() | |
else if role_middleware_array.length is 0 or allowed is false # all middleware behind, still no explicit access | |
res.send(403) |
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
save_path = 'c:\links.html' | |
require 'capybara' | |
Capybara.current_driver = :selenium | |
include Capybara::DSL | |
visit 'http://docs.angularjs.org/api/' | |
def to_static link | |
link.sub 'docs.angularjs.org', 'docs.angularjs.org/?_escaped_fragment_=' | |
end | |
links = all('.api-list-item.nav-list a').map do |e| | |
"<a href=\"#{to_static(e[:href])}\"> #{e.text.strip}</a>" |