Skip to content

Instantly share code, notes, and snippets.

@walidvb
walidvb / count_database_rows.rb
Created September 2, 2021 14:01
Count all rows from all tables on rails
class DatabaseReport
def entry_counts
tables = table_model_names.map do |model_name|
entity = model_name.constantize rescue nil
next if entity.nil?
[entity.to_s, entity.count]
end.compact
total = tables.reduce(0) do |acc, curr|
puts "#{curr[0]}: #{curr[1]}"
acc + curr[1]
@walidvb
walidvb / SearchableContext.js
Created April 2, 2020 21:06
Resettable Searchable Dropdown – via Context
// 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>)
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';
@walidvb
walidvb / Category.js
Created March 11, 2020 14:52
zippax help
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 / Gemfile
Created May 20, 2016 16:23
RailsAdmin config for translatable models
#### I18n
gem 'rails-i18n', '~> 4.0.0'
gem 'globalize'
gem 'rails_admin', github: 'sferik/rails_admin'
gem 'rails_admin_globalize_field'
@walidvb
walidvb / spotify_snippet.js
Last active November 15, 2019 20:36
Get spotify playlist tracks as a list
// 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 November 13, 2019 21:25
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
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 February 7, 2019 13:31
Eric Cloutier's chill spotify playlist
[
{
"artist":"Drowning the Call",
"song":"Mirrorring"
},
{
"artist":"Replicant",
"song":"Sync24"
},
{
@walidvb
walidvb / sample-events.json
Last active February 22, 2018 02:48
Sample batched events sent by sendgrid webhook
[
{
"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 19:00
Fetching a node context from url alias
<?php
function my_module_ctools_plugin_directory($module, $plugin) {
if ($module == 'ctools' && !empty($plugin)) {
return "plugins/$plugin";
}
}