Skip to content

Instantly share code, notes, and snippets.

View martsie's full-sized avatar

Marton Bodonyi martsie

View GitHub Profile
@martsie
martsie / App.tsx
Created January 31, 2022 04:13
Reduce motion linked up to animations
import React, { useEffect, useRef, useState } from 'react';
import {
StyleSheet,
Text,
View,
Animated,
TouchableOpacity,
Pressable,
} from 'react-native';
import { useReduceMotion } from './src/hooks/useReduceMotion';
@martsie
martsie / useReduceMotion.ts
Created January 31, 2022 02:51
useReduceMotion hook for ReactNative
import { useEffect, useState } from 'react'
import { AccessibilityInfo } from 'react-native'
// Adapted from https://github.com/infiniteluke/react-reduce-motion/blob/master/src/targets/native/index.js
export const useReduceMotion = (): boolean => {
const [shouldReduceMotion, setShouldReduceMotion] = useState(false)
useEffect(() => {
const handleChange = (isReduceMotionEnabled: boolean): void => {
setShouldReduceMotion(isReduceMotionEnabled)
@martsie
martsie / helpers.php
Created July 30, 2020 21:58
Split a name into first name and last initial without UTF8 malformed errors
<?php
function convertName($full_name) {
$split_name = explode(' ', $full_name);
if (count($full_name) !== 2) {
// Single word name.
return $full_name;
}
// Must use mb_substr otherewise utf8 issues can occur with foreign names.
return mb_substr($split_name[0], 0, 1) . ' ' . mb_substr($split_name[1], 0, 1) . '.';
@martsie
martsie / MyComponent.js
Created June 10, 2020 06:02
Lewagon #404 Component template
const MyComponent = (rootElement) => {
const subEl = rootElement.querySelector('.js-some-btn');
console.log(rootElement, "i'm working!");
};
export default MyComponent;
@martsie
martsie / MyPlugin.js
Last active November 26, 2019 05:44
Lewagon Vanilla JS Plugin template
/*
Example safe-executing JS script for Lewagon.
packs/plugins/myPlugin.js
*/
export const initMyPlugin = (selector) => {
const elements = Array.from(document.querySelectorAll(selector));
return elements.map(el => new MyPlugin(el));
};
@martsie
martsie / package.json
Last active February 5, 2022 20:50
Purge CSS in Create React App without ejecting
{
"name": "my-app",
"version": "0.1.0",
"private": true,
"dependencies": {
"react": "^16.8.6",
"react-dom": "^16.8.6",
"react-scripts": "3.0.1"
},
"devDependencies": {
@martsie
martsie / custom.js
Created July 20, 2017 01:18
Update auto positioned leaflet tooltips on map pan
leafletElement.eachLayer(function(layer) {
// Re-render tooltips that have automatic positioning on map pan events.
if(layer.options.direction && layer.options.direction === 'auto') {
layer.update();
}
});
@martsie
martsie / my_custom_module.module
Created January 25, 2017 11:18
Sample Drupal 7 module hook
<?php
/**
* @file
* A description of the code contained in this file.
*/
/**
* Implements hook_init().
*/
function my_custom_module_init() {
@martsie
martsie / my_custom_module.info
Created January 25, 2017 11:17
Sample Drupal 7 module info file
name = My custom module
description = Runs some hooks and PHP code.
package = All of my modules
core = 7.x
; Our module depends on node.
dependencies[] = node
; Our module could include views handlers.
; files[] = my_custom_module.views.inc
@martsie
martsie / my_custom_module.js
Created January 25, 2017 11:08
Drupal 7 AJAX commands javascript implementation
(function ($) {
Drupal.behaviors.my_custom_module = {
attach: function(context, settings) {
// Use context to ensure the link is only ever activated if it's regenerated.
var $mySpecialLink = $('#my-special-link', context);
// Only run if the link exists in the current page load or fragment refresh.
if ($mySpecialLink.size() > 0) {
new Drupal.ajax('#my-special-link', $mySpecialLink, {
url: $mySpecialLink.attr('href'),