Skip to content

Instantly share code, notes, and snippets.

View gabrielecanepa's full-sized avatar
🇮🇹
in italy

Gabriele Canepa gabrielecanepa

🇮🇹
in italy
View GitHub Profile
@gabrielecanepa
gabrielecanepa / is-touch-device.js
Last active March 11, 2024 14:57
JavaScript snippet to check if a device supports touch gestures.
const isTouchDevice = () => !!('ontouchstart' in window) || !!('msmaxtouchpoints' in window.navigator)
@gabrielecanepa
gabrielecanepa / gatsby-node.js
Last active April 7, 2020 23:18
Enable absolute imports in Gatsby
const path = require('path');
exports.onCreateWebpackConfig = ({ stage, actions }) => {
actions.setWebpackConfig({
resolve: {
modules: [path.resolve(__dirname, 'src'), 'node_modules'],
},
});
}
@gabrielecanepa
gabrielecanepa / animal.rb
Last active April 7, 2020 22:55
Ruby MVC example @lewagon
# Assign costants at the top of the file.
# Use capital letters for the name, and the #freeze method on the object
PHYLA = %w[Ecdysozoa Lophotrochozoa Radiata Deuterostomia].freeze
class Animal
attr_reader :name
def initialize(name)
@name = name
end
@gabrielecanepa
gabrielecanepa / ruby-lamdbas.md
Last active April 7, 2020 23:17 — forked from Integralist/Ruby Lambdas.md
Ruby Lambdas

Ruby Lambdas

Lambda: standard

# Creating a lambda
l = lambda { |name| "Hi #{name}!" }

# Executing the lambda
l.call("foo") # => Hi foo!
@gabrielecanepa
gabrielecanepa / rails-http.md
Last active April 7, 2020 23:16 — forked from mlanett/rails http status codes
HTTP status code symbols in Rails

HTTP in Rails

Code Symbol About
1xx Informational
100 :continue
101 :switching_protocols
102 :processing
2xx Success
200 :ok
@gabrielecanepa
gabrielecanepa / mixins.scss
Last active April 29, 2020 01:52 — forked from hofmannsven/README.md
Sass Cheatsheet
// Useful Mixins
@mixin shadow($x, $y, $blur, $color) {
box-shadow: $x $y $blur $color;
}
@mixin animate($property: all, $duration: 1s, $easing: ease) {
transition: $property $duration $easing;
}
// 1. null vs. undefined
// null is a value, representing "nothing"
// undefined means that the variable was never assigned
const nullValue = null
const undefinedValue = undefined
let name // I declare this variable, but I don't assign it
console.log(name) // => undefined
@gabrielecanepa
gabrielecanepa / algolia-settings-sync.js
Last active June 21, 2022 23:53
⏱ Simple script to copy Algolia's settings, synonyms and rules from one index to all others in the same app.
/**
* Script to copy Algolia's settings, synonyms and rules from one index to all others in the same application.
*/
import algoliasearch from 'algoliasearch'
const client = algoliasearch('APP_ID', 'ADMIN_API_KEY')
const sourceIndex = client.initIndex('SOURCE_INDEX_NAME')
const copySettings = async (source, target) => {
import algoliasearch from 'algoliasearch'
import searchInsights from 'search-insights'
import { chunks } from './utils.js'
const APP_ID = 'YOUR_APP_ID'
const API_KEY = 'YOUR_SEARCH_API_KEY'
const INDEX_NAME = 'YOUR_INDEX_NAME'
const FACET_NAME = 'categories' // change this value according to your configuration
const client = algoliasearch(APP_ID, API_KEY)
@gabrielecanepa
gabrielecanepa / sync-query-suggestions.js
Created March 3, 2023 14:07
Sync Algolia query suggestion using the current index configuration.
import algoliasearch from 'algoliasearch'
const INDEX_NAME = 'SOURCE_INDEX_NAME' // e.g. 01uat_hmkw_en
const QUERY_SUGGESTIONS_INDEX_NAME = 'QUERY_SUGGESTIONS_INDEX_NAME' // e.g. 01uat_hmkw_en_query
const NEW_QUERY_SUGGESTIONS_INDEX_NAME = 'NEW_QUERY_SUGGESTIONS_INDEX_NAME' // e.g. 01uat_hmkw_en_query_suggestions
const FACET_NAME = 'CATEGORY_FACET_NAME' // e.g. field_category_name.lvl0
const client = algoliasearch('APP_ID', 'API_KEY')
const querySuggestionsIndex = client.initIndex(QUERY_SUGGESTIONS_INDEX_NAME)
const newQuerySuggestionsIndex = client.initIndex(NEW_QUERY_SUGGESTIONS_INDEX_NAME)