Skip to content

Instantly share code, notes, and snippets.

View dhonig's full-sized avatar

Daniel Honig dhonig

View GitHub Profile
@dhonig
dhonig / search.js
Created January 11, 2020 21:47
mongosearch
// Requires official Node.js MongoDB Driver 3.0.0+
var mongodb = require("mongodb");
var client = mongodb.MongoClient;
var url = "mongodb://host:port/";
client.connect(url, function (err, client) {
var db = client.db("test");
var collection = db.collection("mains");
query{
products{
id
images{
attachment {
url
}
}
optionTypes {
edges {
@dhonig
dhonig / merge_sort.js
Created April 18, 2017 12:02
Merge sort in Javascript
class Mergesort{
constructor(numbers){
this.numbers=numbers;
}
merge(left, right){
var result=[];
console.log("Left:"+left);
console.log("Right"+right);
@dhonig
dhonig / Inversions.js
Created April 18, 2017 11:58
Count Integer Inversions by modifying merge sort
class Inversioncount{
constructor(numbers){
this.numbers=numbers;
this.count=0;
}
merge(left, right){
var result=[];
@dhonig
dhonig / find_inversions.js
Created April 17, 2017 02:21
Linear version of find all integer inversions
function getInversionCount(arr){
var inv_count = 0;
var n=arr.length
for (var i = 0; i < n - 1; i++)
for (var j = i+1; j < n; j++)
if (arr[i] > arr[j])
inv_count++;
return inv_count;
}
@dhonig
dhonig / solution.ex
Created July 25, 2016 02:28
Progammiung in Elixir Exercise 4
prefix= fn doputs -> fn(s) -> IO.puts "#{s}" end end
cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing on host 52.88.81.221: scp: /tmp/cardfool/git-ssh.sh: Permission denied
/Users/Daniel/.rvm/gems/ruby-2.1.2/gems/net-scp-1.2.1/lib/net/scp.rb:398:in `await_response_state'
/Users/Daniel/.rvm/gems/ruby-2.1.2/gems/net-scp-1.2.1/lib/net/scp.rb:369:in `block (3 levels) in start_command'
/Users/Daniel/.rvm/gems/ruby-2.1.2/gems/net-ssh-2.9.1/lib/net/ssh/connection/channel.rb:311:in `call'
/Users/Daniel/.rvm/gems/ruby-2.1.2/gems/net-ssh-2.9.1/lib/net/ssh/connection/channel.rb:311:in `process'
/Users/Daniel/.rvm/gems/ruby-2.1.2/gems/net-ssh-2.9.1/lib/net/ssh/connection/session.rb:222:in `block in preprocess'
/Users/Daniel/.rvm/gems/ruby-2.1.2/gems/net-ssh-2.9.1/lib/net/ssh/connection/session.rb:222:in `each'
/Users/Daniel/.rvm/gems/ruby-2.1.2/gems/net-ssh-2.9.1/lib/net/ssh/connection/session.rb:222:in `preprocess'
/Users/Daniel/.rvm/gems/ruby-2.1.2/gems/net-ssh-2.9.1/lib/net/ssh/connection/session.rb:205:in `process'
Rails.application.routes.draw do
# This line mounts Spree's routes at the root of your application.
# This means, any requests to URLs such as /products, will go to Spree::ProductsController.
# If you would like to change where this engine is mounted, simply change the :at option to something different.
#
# We ask that you don't use the :as option here, as Spree relies on it being the default of "spree"
mount Spree::Core::Engine, :at => '/'
Spree::Core::Engine.add_routes do
namespace :api do
Rails.application.routes.draw do
# This line mounts Spree's routes at the root of your application.
# This means, any requests to URLs such as /products, will go to Spree::ProductsController.
# If you would like to change where this engine is mounted, simply change the :at option to something different.
#
# We ask that you don't use the :as option here, as Spree relies on it being the default of "spree"
mount Spree::Core::Engine, :at => '/'
Spree::Core::Engine.add_routes do
namespace :api do
Spree::Shipment.class_eval do
audited associated_with: :order
has_associated_audits
def transfer_to_shipment(variant, quantity, shipment_to_transfer_to)
quantity_already_shipment_to_transfer_to = shipment_to_transfer_to.manifest.find{|mi| mi.line_item.variant == variant}.try(:quantity) || 0
if (quantity <= 0 || self == shipment_to_transfer_to)