Skip to content

Instantly share code, notes, and snippets.

@walidvb
walidvb / SearchableContext.js
Created Apr 2, 2020
Resettable Searchable Dropdown – via Context
View SearchableContext.js
// this is an attempt at not adding redux just yet
import React, { createContext, useContext, useCallback, useEffect, useState } from 'react'
const Context = createContext({})
const Provider = React.memo(({ value, children }) => <Context.Provider value={value}>
{children}
</Context.Provider>)
View TrackSessions.js
import React, { useState } from 'react';
import { View, ScrollView, RefreshControl, TouchableOpacity, StyleSheet } from 'react-native';
import axios from 'axios'
import { dateAndTime } from '../../utils/dateFormatter';
import { List, Text } from '../../components/ui';
import i18n from 'i18n-js';
import AddSession from "../../assets/images/addSession.svg"
import trackStore from '../sessions/trackStore'
import routes from '../../helpers/routes';
import Colors from 'app/constants/Colors';
View Category.js
import { useState, useEffect }, React from 'react'
const categoriesURL = (id) => `your-url/categories`
export default Category () => {
const [categories, setCategories] = useState([])
useEffect(() => {
fetch(categoriesURL).then(res => res.json()).then(data => setCategories(data))
}, [])
@walidvb
walidvb / spotify_snippet.js
Last active Nov 15, 2019
Get spotify playlist tracks as a list
View spotify_snippet.js
// how to use:
// on embed: https://share.getcloudapp.com/d5ub5A0K
// on playlist
(function(document){
let { wrapper, rowClass, nameClass, artistClass } = getSelectors();
var container = document.createElement('textarea');
document.body.appendChild(container)
var results = [...wrapper.querySelectorAll(rowClass)].map(s => {
@walidvb
walidvb / _requestPermissions_example.js
Last active Nov 13, 2019
This allows displaying a dialog to the user before actually requesting permissions from the OS. Ultimately, it allows to request that permission multiple times, which iOS prevents
View _requestPermissions_example.js
import requestPermissions from './requestPermissions'
requestPermission(pickFromCamera, {
permissionNames: ['CAMERA', 'CAMERA_ROLL'],
alertTitle: '📷Camera📸',
alertBody: 'Use your camera now.',
})
// Only request every n times this is run
@walidvb
walidvb / Eric Cloutier.json
Last active Feb 7, 2019
Eric Cloutier's chill spotify playlist
View Eric Cloutier.json
[
{
"artist":"Drowning the Call",
"song":"Mirrorring"
},
{
"artist":"Replicant",
"song":"Sync24"
},
{
@walidvb
walidvb / sample-events.json
Last active Feb 22, 2018
Sample batched events sent by sendgrid webhook
View sample-events.json
[
{
"timestamp":1519267261,
"event":"processed",
"sg_message_id":"14c5d75ce93.dfd.64b469.filter0001.16648.5515E0B88.0",
"smtp-id":"<14c5d75ce93.dfd.64b469@ismtpd-555>",
"sg_event_id":"2FeCcG5VRWpck6mKqRgnDg==",
"category":"cat facts",
"email":"example@test.com"
},
@walidvb
walidvb / my_module.module.php
Created May 24, 2017
Fetching a node context from url alias
View my_module.module.php
<?php
function my_module_ctools_plugin_directory($module, $plugin) {
if ($module == 'ctools' && !empty($plugin)) {
return "plugins/$plugin";
}
}
@walidvb
walidvb / parallax.js
Created Mar 25, 2017
Mapping 2017 parallax code
View parallax.js
let $back;
const BACKGROUND_ID = '#background', SCROLL_SELECTOR = 'main';
//hard-coded backgoround image size to start parallax asap
let sizes = {
width: 1678, height: 2481
};
$(document).on('turbolinks:load', () => {
$(scrollSelector).on('scroll', handleParallax);
setSize();
@walidvb
walidvb / Gemfile
Created May 20, 2016
RailsAdmin config for translatable models
View Gemfile
#### I18n
gem 'rails-i18n', '~> 4.0.0'
gem 'globalize'
gem 'rails_admin', github: 'sferik/rails_admin'
gem 'rails_admin_globalize_field'