Skip to content

Instantly share code, notes, and snippets.

View hrdwdmrbl's full-sized avatar
👨‍🎨
Creating

Marc Bee hrdwdmrbl

👨‍🎨
Creating
View GitHub Profile
@hrdwdmrbl
hrdwdmrbl / delete-left.rb
Created April 5, 2023 00:06
This script processes jdupes output to always deletes from witin the given directory
#!/usr/bin/env ruby
# This script processes jdupes output to always deletes from witin the given directory
# Example usage: `$ jdupes -r dir1 dir2 | ./delete-left.rb -d dir1`
require 'optparse'
options = {}
OptionParser.new do |opts|
opts.banner = "Usage: delete-left.rb [options]"
@hrdwdmrbl
hrdwdmrbl / interview.md
Last active May 21, 2021 16:35
Interview Questions

Topic: REST

Q. Can you tell me what a RESTful API is and isn't?

A. Technically it means that the server holds no state. All state comes from the client. All API endpoints each serve a single purpose.

Topic: Rails

Q. What is CSRF and how does Rails protect against it?

A. Cross Site Request Forgery is when one website tries tells your browser to make a rquest to another website. Rails prevents this by embedding a secret token on its page that you have to give it back when you make a request. Other websites won't have that token.

@hrdwdmrbl
hrdwdmrbl / default_rails_webpack_config.json
Last active June 22, 2020 20:16
Mostly default Rails 6 Webpacker config
{
"loaders": [
{
"key": "file",
"value": {
"test": {},
"use": [
{
"loader": "file-loader",
"options": {
@hrdwdmrbl
hrdwdmrbl / -Shopify-Sendy.md
Created May 5, 2020 17:18 — forked from ridem/-Shopify-Sendy.md
Synchronize Shopify customers with Sendy

Synchronize Shopify customers with Sendy subscribers

Sendy woudln't be the Mailchimp killer without a proper Shopify integration. There we go, thanks to the Shopify gem and some ActiveRecord awesomeness.

NB: The script always keep in sync Shopify's accepts_marketing field with Sendy's unsubscribed field. I added custom fields like country and order count as an example of what we can do with it.

Installation

First make sure that you have the right ruby install (with rbenv for instance), with the right gems installed (like activerecord, shopify_api, etc) and the right mysql packages for the activerecord adapter;

### Keybase proof
I hereby claim:
* I am hrdwdmrbl on github.
* I am hrdwdmrbl (https://keybase.io/hrdwdmrbl) on keybase.
* I have a public key whose fingerprint is 65EA 50A3 8EC0 F4D4 8A34 F54C D754 F61B 08EF C015
To claim this, I am signing this object:
@hrdwdmrbl
hrdwdmrbl / ability.rb
Created June 5, 2013 23:06
CanCan -- HowTo cache the ability.rb file
class Ability
include CanCan::Ability
def marshal_dump
#blocks cannot be cached
@rules.reject{|rule| rule.instance_variable_get :@block }.map{|rule| Marshal.dump(rule) }
end
def marshal_load array
#blocks cannot be cached, so blocks must be re-defined
can :read, Comment do |comment|
@hrdwdmrbl
hrdwdmrbl / strong_paramters_permitted_scaler_values.rb
Created June 5, 2013 22:56
Strong Parameters -- HowTo Custom PERMITTED_SCALAR_TYPES
# config/initializers/strong_paramters_permitted_scaler_values.rb
ActionController::Parameters.send :define_method, :permitted_scalar? do |value|
[String,
Symbol,
NilClass,
Numeric,
TrueClass,
FalseClass,
Date,
@hrdwdmrbl
hrdwdmrbl / ruby_on_rails_count_definitions
Created December 16, 2011 15:29
Digging deeper into array#count
class CompanyProfile < ActiveRecord::Base
has_many :companies, :through => :companies_company_profiles
has_many :companies_company_profiles
end
class Company < ActiveRecord::Base
has_many :company_profiles, :through => :companies_company_profiles
has_many :companies_company_profiles
end
@hrdwdmrbl
hrdwdmrbl / ruby_on_rails_count_monkeypatch
Created December 16, 2011 15:13
Count does not work
companies.count
=> 3
companies.class
=> Array
companies[0]
=> #<Company id: 7, name: "company10", logo: nil, description: nil, number_of_employees: nil, creation_date: nil, headquarters: nil, website: nil, feed: nil, blog: nil, public_page: true>
companies[1]
=> #<Company id: 12, name: "HuWhere", logo: nil, description: "", number_of_employees: 2, creation_date: "2011-11-11", headquarters: "Montreal", website: "google.com", feed: "google.com", blog: "www.google.com", public_page: true>
companies[2]
=> #<Company id: 14, name: "HuWhere", logo: nil, description: "", number_of_employees: 2, creation_date: "2011-11-11", headquarters: "Montreal", website: "google.com", feed: "google.com", blog: "www.google.com", public_page: true>