Skip to content

Instantly share code, notes, and snippets.

View trivektor's full-sized avatar
🏠
Working from home

Tri Vuong trivektor

🏠
Working from home
View GitHub Profile
@kartikkukreja
kartikkukreja / Maximum Subarray Problem.py
Last active August 29, 2015 14:04
Maximum Subarray Problem
let A be the given array of integers
let maxSum = -infinity, maxLeft = 0, maxRight = 0, currentMax = 0, left = 0, right = 0
for i = 0 to A.length - 1
currentMax += A[i]
if currentMax > maxSum
maxSum = currentMax
right = i;
maxLeft = left
maxRight = right
if currentMax < 0
module ActiveRecord
class Base
def self.random
if (c = count) != 0
find(:first, :offset =>rand(c))
end
end
end
end
@clm-a
clm-a / index-with-fields_for.html.erb
Created March 16, 2011 09:44
Howto : work with index in Rails 3's fields_for
<%= form_for parent do |parent_form_builder| %>
<%= parent_form_builder.text_field :name %>
<% parent.children.each_with_index do |child, index| %>
<% parent_form_builder.fields_for :children, child do |child_form_builder| %>
<%= child_form_builder.select :age, (0..99).to_a %>
<%# generates "parent[:children_attributes][index][age]" as name for the input %>
<% end %>
<% end %>
<%= f.submit %>
<% end %>
@thegrubbsian
thegrubbsian / backbone_event_proxy.js
Created July 30, 2011 15:56
Backbone.js Proxy Event Method
Backbone.View.prototype.proxy = function(source, eventName, options) {
if (!options) { options = {}; }
var self = this;
source.bind(eventName, function(args) {
var name = options["proxyName"] || eventName;
var newArgs = options["proxyArgs"] ? _.combine(args, options["proxyArgs"]) : args;
self.trigger(name, newArgs);
});
};
@leucos
leucos / config.ru
Created December 11, 2011 14:43
ORA-12154 with Sequel and daemonized Thin
# Invoked with :
# thin -DR config.ru start
# (single, undetached process, oracle Ok)
# thin -DR config.ru -s2 start
# (two forked processed, oracle error ORA-12154)
$LOAD_PATH << File.expand_path(File.dirname(__FILE__))
require 'rack'
require 'init.rb'
@iros
iros / add_duplication_check.js
Created December 22, 2011 18:03
Backbone Blog Post :: Live Collections
// A collection holding many tweet objects.
// also responsible for performing the
// search that fetches them.
var Tweets = Backbone.Collection.extend({
model: Tweet,
initialize: function(models, options) {
this.query = options.query;
},
url: function() {
return "http://search.twitter.com/search.json?q=" + this.query + "&callback=?";
@lamikae
lamikae / jhw-assets.md
Created February 5, 2012 12:28
Jasmine headless testing on Rails 3 asset pipeline

Jasmine headless testing on Rails 3 asset pipeline

  • assets and specs can be CoffeeScript
  • 3rd party JS can be placed to vendor/assets/javascripts or vendor gems
  • detects gem-vendored JS via application.js require
  • uses jasmine-headless-webkit to run the suite outside the browser
    • this requires Qt4.7 installation
@mattheworiordan
mattheworiordan / compile.rb
Created February 15, 2012 19:39
Rails assets compilation using the correct RAILS_ENV into a Git branch
#!/usr/bin/env ruby
##
# Compile script for Rails assets that puts the assets into their [environment] branch
# thus not polluting the master branch with the files in public/assets that only
# apply to that environment. See https://github.com/rails/sass-rails/issues/93#issuecomment-3982582
#
# Usage: ./compile [environment]
# supported environments
@cecilemuller
cecilemuller / _extensions.js
Created March 4, 2012 12:59
Animated pushpins in Bing Maps AJAX 6.3
/**
* This snipplet adds the following methods:
* VEMap.DropPushpin
* VEShapeLayer.DropPushpin
*
* This is similar to VEMap.AddPushpin except the pin is animated (it "falls" on the map).
*
* Works even in IE6 and the IPhone. Generic solution based on this proof of concept:
* http://www.garzilla.net/vemaps/DropPushPin.aspx
*/
@achambers
achambers / gist:2305759
Created April 4, 2012 21:19
Install instantclient in Linux
digital-alley:tmpdir aaron$ vagrant up
digital-alley:tmpdir aaron$ vagrant ssh
vagrant@lucid32:~$ sudo apt-get install unzip
vagrant@lucid32:~$ sudo apt-get install rpm
vagrant@lucid32:~$ cd /tmp
vagrant@lucid32:~$ cp /vagrant/instantclient-* .
vagrant@lucid32:~$ cd /opt
vagrant@lucid32:~$ sudo mkdir oracle
vagrant@lucid32:~$ cd oracle