Skip to content

Instantly share code, notes, and snippets.

View nhobi's full-sized avatar
🌼

Nate nhobi

🌼
View GitHub Profile
@nhobi
nhobi / calculateDownloadSpeed.js
Last active May 6, 2021 22:59
Calculates the download speed of your current network based on an image fixture.
export default () => {
return new Promise((resolve, reject) => {
let imageAddr =
"https://nhmisc.s3.amazonaws.com/liswall/stub.jpg" +
"?n=" +
Math.random();
let startTime, endTime;
let downloadSize = 1025385;
let download = new Image();
@nhobi
nhobi / uploadBlob.js
Created May 6, 2021 22:56
Uploads a given blob to S3.
import random from "./randomString";
function getBucketObj() {
AWS.config.region = window.aws.region; // 1. Enter your region
AWS.config.credentials = new AWS.Credentials(aws.key, aws.secret);
AWS.config.credentials.get(function(err) {
if (err) alert(err);
});
@nhobi
nhobi / keepIndexInBounds.js
Created May 6, 2021 22:50
A Vue mixin that handles keeping the index for a given collection in bounds.
export default (collectionName, indexName = "selectedIndex", cycle = false) => {
return {
watch: {
[indexName](newValue, oldValue) {
if (this[collectionName] === undefined) {
return;
}
let highestIndex = this[collectionName].length - 1;
@nhobi
nhobi / listeningWallBuilderStore.js
Created May 3, 2021 05:44
An example VueX store from Listening Wall.
import { createNamespacedHelpers } from "vuex";
import Axios from "axios";
import { getHelperWords, getWordObj } from "../functions/helperWords";
import builderUtils from "../functions/builderUtils";
import randomString from "../functions/randomString";
export default {
...createNamespacedHelpers("builder"),
namespaced: true,
// Fonts
@import url("https://fonts.googleapis.com/css?family=Nunito");
// Variables
@import "variables";
@import "keyframes";
@import "animations";
// Bootstrap
@import "~bootstrap/scss/bootstrap";
@nhobi
nhobi / cloudinary.sh
Last active May 20, 2019 16:14
Network Request
# Note: Both these requests are being fired by the cloudinary medialibrary js code, not my code.
# Works! This is 'copy as curl' from Chrome, where I don't get the 401 error.
curl 'https://cloudinary.com/console/api/v1/auth/login_from_session' \
-H 'pragma: no-cache'
-H 'cookie: _ga=GA1.2.813819547.1538000561; __utma=136482402.813819547.1538000561.1557868798.1557868798.1; __utmz=136482402.1557868798.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); _mkto_trk=id:396-LRB-524&token:_mch-cloudinary.com-1557868798202-41547; intercom-session-f8c4avgs=eU9ZUWlHa3M4SGRKdmMrTjZKU2cvM2FwNkc2blRiaFVoNnFqOHp6OGxVWFBtREo3cFZxOWdCNnNQVnM3cjR2Ry0td2FtY083YVlQY1F1dXQvNXAzRERNQT09--23ea95a8522a7e2e61e0f2a9d427399076fffd0b; new_ml_enabled=yes; _cld_session_key=9a4aad31e7fdfb49e8c2d84aa0058260; _gid=GA1.2.1358471984.1558366586; _gat_UA-25966579-7=1; AWSALB=KOnDJDzN5FvI0QMXbBowU1lYTxi1xdSr8cQEJIDYz2uVPho7FamV++d8iSWr6moSaze+QFXg9Q3s+zK6VB+gL7CIXsU9TGaPImTHfZh9NWD06pHOG4dWJX9hhTl4'
-H 'accept-encoding: gzip, deflate, br' \
@nhobi
nhobi / keyByRecursive.php
Last active June 15, 2023 23:43
Collection keyByRecursive macro
<?php
Illuminate\Support\Collection::macro('keyByRecursive', function ($func) {
return $this->keyBy(function ($value, $key) use ($func) {
return $func($value, $key);
})->map(function ($item) use ($func) {
<snippet>
<content><![CDATA[
this.${1:func} = this.${1:func}.bind(this);
]]></content>
<description>Bind class methods in constructor for React components.</description>
<tabTrigger>bind</tabTrigger>
<scope>source.js</scope>
</snippet>
@nhobi
nhobi / rncom.sublime-snippet
Created April 17, 2017 14:40
New React Native Component
<snippet>
<content><![CDATA[
import React, { Component } from "react";
import {
View,
Text,
TouchableWithoutFeedback,
Image,
Animated
} from "react-native";
@nhobi
nhobi / find_base64_eval.php
Created December 1, 2016 18:18
Use this script (that I didn't write) to look for malicious code on your server.
<html><head><title>Find String</title></head><body>
<?php
// ini_set('max_execution_time', '0');
// ini_set('set_time_limit', '0');
find_files('.');
function find_files($seed) {
if(! is_dir($seed)) return false;
$files = array();
$dirs = array($seed);
while(NULL !== ($dir = array_pop($dirs)))