Skip to content

Instantly share code, notes, and snippets.

View ivanlawrence's full-sized avatar

Ivan Lawrence ivanlawrence

View GitHub Profile
@ivanlawrence
ivanlawrence / loop_load_from_infile.sh
Last active September 10, 2024 20:32
MySQL dump from cloudSQL then convert to load infile for local import
#!/usr/bin/bash
set -e
# Loops through a hardcoded list of dbs
# The hard coded parts are the db names since they need to exist, and the create table command is taken manually from the mysqldump
transform_files () {
if ! [ -f ${file_src} ]
then
echo "file ${file_src} not found"
@ivanlawrence
ivanlawrence / gist:fd5363364db887f6e1cd33c385ba1a61
Created January 17, 2024 21:36
VSCode \ VSCodium Extensions I use
# But Why Though
A good article on how to do it with builtins
(https://www.roboleary.net/2021/11/06/vscode-you-dont-need-that-extension2.html)
# VSCode
## Default
Name: Dev Containers
Id: ms-vscode-remote.remote-containers
Description: Open any folder or repository inside a Docker container and take advantage of Visual Studio Code's full feature set.
Version: 0.327.0
@ivanlawrence
ivanlawrence / fooUtil.js
Last active September 15, 2020 21:32
Create a JS utilities object to keep and protect reusable functions
Object.defineProperty(window, 'foo', {
enumerable: false,
configurable: false,
writable: false,
value: (function() {
function FooUtility() {};
// a Pseudo constructor which makes some protected methods which protect things
Object.defineProperties(FooUtility.prototype, {
'version': { value: 2.0 },
// The following allows us to build-up a function/object and control if the properties are overwrite-able or not
@ivanlawrence
ivanlawrence / jsPubSubObj.js
Last active August 27, 2020 05:58
A JS pubsub pattern as an object, nothing fancy
const jsPubSub = {
subscriptions: {
clearTopicSubscriptions(topic) {
if (!this[topic]) return;
return delete this[topic];
},
},
@ivanlawrence
ivanlawrence / JsPubSubClass.js
Last active August 27, 2020 05:59
A simple pubsub pattern for JS in a class with an unsubscribe per subscription and a "crear" for all subscribers of an event
class JsPubSub {
constructor() {
this.subscriptions = {
clearTopicSubscriptions(topic) {
if (!this[topic]) return;
delete this[topic];
},
};
@ivanlawrence
ivanlawrence / gist:5edd8a5fc49c10f7a7f6573f9607b4a1
Created July 24, 2020 18:02
Magic Formula Investing - download - bookmarklet
javascript:(function(){
let csv = []
// loop through each row
$('#tableform').find('tr').each(function() {
let row = [];
// loop through each cell in a row
$(this).find('th,td').each(function() {
// add to the row array
row.push( '"' + $(this).text().trim() + '"' );
});
@ivanlawrence
ivanlawrence / gist:57deb49a10a04c44fda2df0b298d1eb9
Last active July 24, 2020 08:53
Magic Formula Investing - copy to clipboard - Bookmarklet
javascript:(function(){
let csv = []
// loop through each row
$('#tableform').find('tr').each(function() {
let row = [];
// loop through each cell in a row
$(this).find('th,td').each(function() {
// add to the row array
row.push( '"' + $(this).text().trim() + '"' );
});
@ivanlawrence
ivanlawrence / joinObjs()
Created May 2, 2019 21:24
So I don't forget
function joinObjs() {
// loops through all arguments and joins them together
const result = {};
for (var i = 0, j = arguments.length; i < j; i++){
Object.keys(arguments[i])
.forEach(key => result[key] = arguments[i][key]);
}
return result;
@ivanlawrence
ivanlawrence / online local JS IDE
Last active May 13, 2019 18:10
A little JS IDE to test some code (download the file and run it in a browser)
<!DOCTYPE html>
<html>
<head>
<title>Local JS IDE</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.4.4/ace.js"></script>
<style>
html,body { margin:0; padding:0; height:100%; width:100%; overflow: hidden;}
#editor {
height: 100%;
... and the next one... its me.