Skip to content

Instantly share code, notes, and snippets.

View frank184's full-sized avatar
👌
pro g[r]amer

François Bélanger frank184

👌
pro g[r]amer
View GitHub Profile
@frank184
frank184 / pet.py
Last active March 14, 2017 23:33
Dynamic Permitted Attribute Assignement & Inheritance in Python
class Pet:
attributes = ['name', 'birthday', 'weight']
def __init__(self, **args):
for attr in self.attributes:
setattr(self, attr, args.get(attr, None))
class Dog(Pet):
dog_attributes = ['breed', 'tricks']
def __init__(self, **args):
Pet.__init__(self, **args)
@frank184
frank184 / ascii.py
Last active March 15, 2017 04:09
Simple ASCII converter CLI in Python
#!/usr/bin/python
import sys
def main():
if len(sys.argv[1:]) < 2:
usage()
elif sys.argv[1] == '-d' or sys.argv[1] == '--decode':
decode(sys.argv[2:])
elif sys.argv[1] == '-e' or sys.argv[1] == '--encode':
encode(" ".join(sys.argv[2:]))
@frank184
frank184 / bell__default_wifi_passwords.rb
Last active March 16, 2017 06:29
BellDefaultWifiPasswords
require 'thor'
module PasswordListGenerators
class BellDefaultWifiPasswords < Thor
CHAR_ARRAY = [*'0'..'9', *'A'..'F'].freeze
TOTAL_PASSWDS = (CHAR_ARRAY.count ** 8).freeze
desc 'generate PATH', 'Generates the password list at the specified path'
def generate(path = 'bell_default_wifi_passwords.txt')
@frank184
frank184 / db.rake
Created November 1, 2016 18:53
Truncate Test DB for when working with `before(:all)`
# /lib/tasks/db.rake
namespace :db do
desc "Truncate all table unless running production"
task :truncate => :environment do
abort("The Rails environment is running in production mode!") if Rails.env.production?
ActiveRecord::Base.logger = Logger.new(STDOUT)
connection = ActiveRecord::Base.connection
connection.execute("SET FOREIGN_KEY_CHECKS=0;")
tables = connection.execute("SHOW TABLES").map{|r| r[0]}
@frank184
frank184 / datatable-ext.js
Created September 21, 2016 23:57
Extending JQuery.DataTable
$.fn.dataTableExt.oApi.reload = function(options) {
this.fnFilter(options['search'])
this.fnPageChange(options['page'])
}
@frank184
frank184 / application_controller.rb
Created September 21, 2016 23:35
Ruby on Rails - I18n implementation
# app/controllers/application_controller.rb
class ApplicationController < ActionController::Base
include Devise::Redirects
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception
include Locale
end
@frank184
frank184 / application.rb
Last active September 21, 2016 23:38
HasSecureToken extension for shoulda-matchers gem while using has_secure_token gem
# config/application.rb
module YourApp
class Application < Rails::Application
# ...
# Auto load lib folder
config.autoload_paths << Rails.root.join('lib')
end
end
@frank184
frank184 / .bash_ps1
Created June 18, 2016 19:30
My bash prompt ¯\_(ツ)_/¯
# Add . "$HOME/.bash_ps1" to .bashrc
export PS1='¯\_(ツ)_/¯\w$ '
@frank184
frank184 / sba_systems_check
Last active June 4, 2016 16:26
SBA Server Statuses Checks
#!/bin/bash
# ~/bin/sba_systems_check
systemctl status mysql --no-pager
systemctl status redis_6379 --no-pager
systemctl status elasticsearch --no-pager
@frank184
frank184 / localtunnel.rake
Created May 21, 2016 16:44
Rake Task that controls the Ruby API for localtunnel
# lib/tasks/localtunnel.rake
namespace :localtunnel do
desc "Starts the LocalTunnel instace"
task start: :environment do
begin
if Rails.env.production?
raise "Trying to launch Localtunnel in production".red
end
default_subdomain = "whatever"
default_port = 3000