Skip to content

Instantly share code, notes, and snippets.

View TheBrotherFromASouthernMother's full-sized avatar

Christian Lowe TheBrotherFromASouthernMother

View GitHub Profile
@TheBrotherFromASouthernMother
TheBrotherFromASouthernMother / newsfeed.jsx
Created November 1, 2023 18:48
The Green Book Project: Newsfeed
import React, { useState, useEffect } from 'react';
import { View } from 'react-native';
import { withAppContext } from 'components/AppContext';
import AppContextShape from 'test_utilities/contexts';
import { Container, Content } from 'native-base';
import IntroductionBanner from 'Notifications/Newsfeed/components/IntroductionBanner';
import LoadMoreButton from 'Notifications/Newsfeed/components/LoadMoreButton';
import EndOfFeedMessage from 'Notifications/Newsfeed/components/EndOfFeedMessage';
import styles from 'Notifications/Newsfeed/styles';
import useGetReviewNewsfeedItems from 'Notifications/Newsfeed/hooks/useGetReviewNewsfeedItems';
@TheBrotherFromASouthernMother
TheBrotherFromASouthernMother / example_newsfeed_schema.js
Created November 1, 2023 18:44
The Green Book Project: Example Newsfeed GraphQL Schema
const {
GraphQLObjectType,
GraphQLString,
GraphQLInt,
GraphQLBoolean,
GraphQLList,
} = require('graphql');
const { DateType } = require('app/schema/shared/types.js');
const { LikeType } = require('app/schema/likes/type.js');
const { UserType } = require('app/schema/user/type.js');
@TheBrotherFromASouthernMother
TheBrotherFromASouthernMother / send_like_push_notification.js
Created November 1, 2023 17:18
Sending a "Like" notification (Node + Bull + Redis + Firebase Cloud Messaging)
const { getReview } = require('app/services/reviews/get.js');
const { getUser } = require('app/services/users/get.js');
const { Sentry, getEnv } = require('app/config.js');
const moment = require('moment-timezone');
const { errorLogger, infoLogger, warnLogger } = require('lib/logger.js');
const { createPushNotification } = require('app/services/push_notifications/create.js');
const { getContactPreferences } = require('app/services/contact_preferences/get.js');
const isEmpty = require('lodash/isEmpty');
const isNil = require('lodash/isNil');
const get = require('lodash/get');
@TheBrotherFromASouthernMother
TheBrotherFromASouthernMother / useHandlePushNotification.js
Created November 1, 2023 16:51
Push Notification Handler (React Native + Hooks)
import { useCallback, useContext } from 'react';
import * as Notifications from 'expo-notifications';
import AppContext from 'components/AppContext';
import isNil from 'lodash/isNil';
import isString from 'lodash/isString';
import get from 'lodash/get';
import { safeParseJSON, getLocalStorageItem } from 'lib/util';
import { DEFAULT_UUID_STORAGE_KEY } from 'Authentication/constants';
import useRecordMassPushNotificationOpen from 'Notifications/hooks/useRecordMassPushNotificationOpen';
import useHandlePushNotificationNavigation from 'Notifications/hooks/useHandlePushNotificationNavigation';
@TheBrotherFromASouthernMother
TheBrotherFromASouthernMother / grid.js
Last active March 12, 2020 00:31
Create Grid Javascript
// uses es6 syntax but can swap out the "lets" and "consts" if you need to use es5
function createGrid(numberOfRowsAndColumns) {
const grid = [];
for (let i = 0; i < numberOfRowsAndColumns; i++) { // upper for-loop creates the rows
const row = [];
for (let j = 0; j < numberOfRowsAndColumns; j++) { / lower for loop creates the individual columns
const columnValue = Math.floor(Math.random() * 100); // generates a random value between 1 and 100
@TheBrotherFromASouthernMother
TheBrotherFromASouthernMother / attempts.haml
Last active August 13, 2019 23:27
Trying to conditionally render a petition card image
Code before changes (compiles and shows petition image):
```
= CommsTemplates.HamlHelpers.one_row_tr %{td: %{ align: 'left'}}, fn ->
%img{src: "{{petition.photo_url}}", class: 'petition-centered-img-lg', style: 'border-radius: 0; margin-right: 0; margin-left: 0;'}
```
Attempt 1 (throws error):
```
- if '{{petition.photo_url}}' do
@TheBrotherFromASouthernMother
TheBrotherFromASouthernMother / Update.sql
Created June 15, 2019 02:44
Updating one column with values from another column (SQL)
Update "table_name" SET "column_B" = "column_A"
@TheBrotherFromASouthernMother
TheBrotherFromASouthernMother / port_process_finding.md
Last active March 18, 2019 18:36
Find the process running on a port

Has it ever happened to you? You attempt to boot up a server instance in the language of your choice (Javascript, Ruby, Python) and you get an error:

Error: A server is already running!

Not too much a problem, you probably just forgot to properly shutdown your server last time you were workring on your personal project. On your local machine the work of finding the still running process isn't too difficult. If you use a Mac like me, you can simply check through the open terminal instances you have running as most manual processes shutdown when you close your terminal.

But maybe you're not trying to boot up a server on your local machine, maybe your server lives in a warehouse of physical servers somewhere very far away on a cloud hosting platform like Heroku or AWS EC2. Worse still, you can't just look in your code and see which port number your server listens to because your software's port is randomly assigned by your cloud hosting provider!

Not to fear!

@TheBrotherFromASouthernMother
TheBrotherFromASouthernMother / unborking_bash_profile.md
Last active March 15, 2019 22:55
Unborking your bash_profile

In my time as an engineer at Change.org I have had to become much more familiar with the command line than I ever thought would be neccessary. Adding variables, secrets passcodes, and api keys to my .bash_profile has become incredibly commonplace in my day-to-day, and all of that has required that I get comfortable using my terminal.

However, despite my growing familiarity with the command line, every once in a while I'll find that I've made a massive mistake (Life of a software developer, am I right?). I'll be going about my day and find out that suddenly I've completely screwed up my bash_profile! Maybe it was an invalid char or a mistake in exporting my $PATH variable, whatever it the mistake may be I find out immediately when I attempt to source my bash_profile and get an error.

"Huh" I think to myself, "I suppose I made a mistake adding that last bash script to my bash_profile, I guess I'll just go back and edit it."

Me: nano ~/.bash_profile

My Terminal: -bash: nano: command not found