This file contains 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
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()) |
This file contains 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
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] |
This file contains 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
#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); | |
} |
This file contains 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
#!/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') |
This file contains 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 JSONRPC < Faraday::Middleware | |
class Error < StandardError | |
attr_reader :code | |
def initialize(message, code) | |
@code = code | |
super(message) | |
end | |
end | |
def call(env) |
This file contains 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
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 |
This file contains 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 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 |
This file contains 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
#!/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 |
This file contains 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 InkHelper | |
class ColumnsCapturer | |
delegate :capture, :content_tag, :to => :@ctx | |
def initialize(ctx, &block) | |
@ctx = ctx | |
@block = block | |
@classes = ['columns'] | |
end |
This file contains 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 'faraday' | |
require 'multi_json' | |
module Google | |
class Geocoder | |
def initialize | |
@conn = Faraday.new('http://maps.googleapis.com/') | |
end | |
# @param [Float] lat |