Skip to content

Instantly share code, notes, and snippets.

from ftplib import FTP, parse227, parse229
import socket
class BetterFTP(FTP):
def makepasv(self):
if self.af == socket.AF_INET:
_, port = parse227(self.sendcmd('PASV'))
else:
_, port = parse229(self.sendcmd('EPSV'), self.sock.getpeername())
import numpy as np
def levinson(acf, p=None):
acf = np.asarray(acf).reshape(-1)
if p is None:
p = len(acf) - 1
# ref = np.zeros(p, dtype=np.complex)
g = -acf[1]/acf[0]
#ifndef __H_CSTRMAP
#define __H_CSTRMAP
#include <cstring>
#include <unordered_map>
struct hash_c_string {
void hash_combine(size_t &seed, const char &v) const {
seed ^= v + 0x9e3779b9 + (seed << 6) + (seed >> 2);
}
#!/usr/bin/env python3
import sys
from keras.models import model_from_json
model = model_from_json(open(sys.argv[1]).read())
print('Loaded model')
model.load_weights(sys.argv[2])
print('Loaded weights')
model.save(sys.argv[3])
print('Saved model')
class JSONRPC < Faraday::Middleware
class Error < StandardError
attr_reader :code
def initialize(message, code)
@code = code
super(message)
end
end
def call(env)
if Rails.env.development? || ENV['LOG_LEVEL'] == 'DEBUG'
Rails.logger.instance_eval { def <<(msg); debug(msg.strip); end }
module Net
class HTTP
def initialize_with_debug(address, port = nil)
initialize_without_debug(address, port)
set_debug_output(Rails.logger)
end
alias :initialize_without_debug :initialize
module PerformLater
def handle_asynchronously(method)
aliased_method, punctuation = method.to_s.sub(/([?!=])$/, ''), $1
with_method, without_method = "#{aliased_method}_with_delay#{punctuation}", "#{aliased_method}_without_delay#{punctuation}"
define_method(with_method) do |*args|
obj = self.is_a?(GlobalID::Identification) ? self : self.to_s
args = args.map { |arg| arg.is_a?(GlobalID::Identification) ? arg : arg.as_json }
Job.perform_later obj, without_method, *args
end
alias_method_chain method, :delay
@romanbsd
romanbsd / builder_builder.rb
Created December 27, 2014 21:04
Create an XmlBuilder from an XML file
#!/usr/bin/env ruby
require 'nokogiri'
class BuilderBuilder
def initialize(file, builder = 'xml')
@doc = Nokogiri::XML(File.read(file))
@builder = builder
end
def to_s
module InkHelper
class ColumnsCapturer
delegate :capture, :content_tag, :to => :@ctx
def initialize(ctx, &block)
@ctx = ctx
@block = block
@classes = ['columns']
end
require 'faraday'
require 'multi_json'
module Google
class Geocoder
def initialize
@conn = Faraday.new('http://maps.googleapis.com/')
end
# @param [Float] lat