Skip to content

Instantly share code, notes, and snippets.

View brunofacca's full-sized avatar

Bruno Facca brunofacca

  • Lifetime Value Co.
  • Portugal
View GitHub Profile
@Puzer
Puzer / optimize_and_predict_daal4py.py
Created April 23, 2021 20:27
LGBM Inference Optimization
import daal4py as d4p
from lightgbm import LGBMClassifier
model = LGBMClassifier()
model.fit(X_data, y_data)
y_pred_orig = model.predict_proba(x_data_dense)[:,1]
daal_model = d4p.get_gbt_model_from_lightgbm(model.booster_)
predictions_container = d4p.gbt_classification_prediction(nClasses=2, resultsToEvaluate='computeClassProbabilities', fptype='float')
@mvervuurt
mvervuurt / ts_ets_decomposition.py
Last active December 4, 2020 21:36
Python Time Series ETS Decomposition
# Assume Pandas DataFrame or Series
#moving average
df.ts_col.rolling(window=6).mean() #example 6 months rolling window
df.ts_col.rolling(window=12).mean() #example 12 months rolling window
#exponentially weighted moving average
df.ts_col.ewm(spane=12).mean()
from statsmodels.tsa.holtwinters import SimpleExpSmoothing
@samredai
samredai / install_pipenv.sh
Created August 12, 2019 18:50
Python: Solution to 'Pipenv: Command Not Found' After 'pip install pipenv'
sudo -H pip install -U pipenv
# If you did a user install because you do not have sudo access, you have to modify your path to add your user folder
# The command on the next line tells you where your user folder is
# python3 -m site --user-base
PYTHON_BIN_PATH="$(python3 -m site --user-base)/bin"
PATH="$PATH:$PYTHON_BIN_PATH"
@tony-gutierrez
tony-gutierrez / AWS_Single_LetsEncrypt.yaml
Last active March 7, 2024 11:29
AWS Elastic Beanstalk .ebextensions config for single instance free SSL using letsencrypt certbot and nginx. http://bluefletch.com/blog/domain-agnostic-letsencrypt-ssl-config-for-elastic-beanstalk-single-instances/
# Dont forget to set the env variable "certdomain", and either fill in your email below or use an env variable for that too.
# Also note that this config is using the LetsEncrypt staging server, remove the flag when ready!
Resources:
sslSecurityGroupIngress:
Type: AWS::EC2::SecurityGroupIngress
Properties:
GroupId: {"Fn::GetAtt" : ["AWSEBSecurityGroup", "GroupId"]}
IpProtocol: tcp
ToPort: 443
@netzfisch
netzfisch / post_policy_spec.rb
Created June 26, 2014 13:51
RSpec example for rails authorisation with Pundit's policy_scope method
describe PostPolicy do
let(:scope) { Post.where(:published => true }
subject(:policy_scope) { PostPolicy::Scope.new(user, scope).resolve }
permissions ".scope" do
context "for an ordinary user"
let(:user) { User.new(:admin => false) }
it "hides unpublished post" do
post = Post.create(:published => false)
# config/routes.rb
resources :documents do
scope module: 'documents' do
resources :versions do
post :restore, on: :member
end
resource :lock
end
end
@spiralx
spiralx / classof.js
Last active February 17, 2017 12:00
An accurate function for getting the type of a variable in JavaScript, using the fact that Object.prototype.toString() is guaranteed to return an object's internal [[Class]] property when called on it. There's also the isclass() helper function that takes an object and one or more class name strings, and returns True if the class of obj matches …
/**
* classof(obj)
*
* Returns the object's internal [[Class]] property, see
* the other file for example output.
*
* @param {Object?} object
* @return {String}
*/
const classof = v => Object.prototype.toString.call(v).replace(/^\[object\s(.*)\]$/, '$1').toLowerCase();
@gkop
gkop / gist:1371962
Created November 17, 2011 00:13
Capture javascript errors in Cucumber+Capybara+Webdriver tests
# in features/support/env.rb
require 'selenium/webdriver'
# we need a firefox extension to start intercepting javascript errors before the page
# scripts load
Capybara.register_driver :selenium do |app|
profile = Selenium::WebDriver::Firefox::Profile.new
# see https://github.com/mguillem/JSErrorCollector
profile.add_extension File.join(Rails.root, "features/support/extensions/JSErrorCollector.xpi")
Capybara::Selenium::Driver.new app, :profile => profile
@vangberg
vangberg / curb.rb
Created December 14, 2010 20:10
persistent http w/ ruby
require "curb"
# Persistent.
c = Curl::Easy.new
c.url = "http://127.0.0.1"
2.times { c.perform }
# Not persistent.
2.times {
c = Curl::Easy.new