Skip to content

Instantly share code, notes, and snippets.

View colonelpopcorn's full-sized avatar

Jonathan Ling colonelpopcorn

View GitHub Profile
@colonelpopcorn
colonelpopcorn / setenv.ps1
Created December 22, 2021 20:09
Set Environment from powershell with .env file
$content = Get-Content "./.env";
$contentArr = $content.Trim().Split([Environment]::NewLine);
ForEach-Object -InputObject $contentArr {
$keyValPair = $_.Split("=", 2);
$key = $keyValPair[0].Trim();
$val = $keyValPair[1].Trim();
$envSign = '$env:'
$afterEnvSign = "$key=$val"
@colonelpopcorn
colonelpopcorn / tryWithDefault.ts
Last active January 29, 2020 21:53
Quick impl of Try.of from VAVR
const tryWithDefault = <T>(func: () => T, defaultVal: T): T => {
try {
return func();
} catch (e) {
// Log or do something here.
// logger.error(e);
return defaultVal;
}
};
@colonelpopcorn
colonelpopcorn / single-file-api.php
Created October 5, 2018 16:10
This is dumb and I like it way more than I should.
<?php
// get the HTTP method, path and body of the request
$method = $_SERVER['REQUEST_METHOD'];
$request = explode('/', trim($_SERVER['PATH_INFO'],'/'));
$input = json_decode(file_get_contents('php://input'),true);
// connect to the mysql database
$link = mysqli_connect('localhost', 'user', 'pass', 'dbname');
mysqli_set_charset($link,'utf8');
@colonelpopcorn
colonelpopcorn / App.ts
Created August 18, 2018 13:40
Parcel problem with hot-reloading
import Vue from 'vue';
import Vuetify from 'vuetify';
import 'vuetify/dist/vuetify.min.css';
import 'material-design-icons-iconfont/dist/material-design-icons.css';
import App from './App.vue';
Vue.use(Vuetify);
Vue.config.productionTip = false;
new Vue({
@colonelpopcorn
colonelpopcorn / .chromerc.js
Last active August 13, 2018 14:53
DotFiles
// ==UserScript==
// @name .chromerc
// @namespace *
// @version 0.1
// @description Utils for debugging
// @author You
// @match *
// @grant none
// ==/UserScript==
# https://stackoverflow.com/questions/12319382/file-system-watcher-event-when-run-using-a-script#12323930
$watcher = new-object System.IO.FileSystemWatcher
$watcher.Path = '.\'
$watcher.Filter = '*.js' # whatever you need
#$watcher.IncludeSubDirectories = $true # if needed
$watcher.EnableRaisingEvents = $true
Register-ObjectEvent $watcher -EventName Changed -SourceIdentifier 'Watcher' -Action { param($sender, $eventArgs)
Write-Host "Detected change in files copying...";
@colonelpopcorn
colonelpopcorn / DownloadJSONObj.js
Last active August 10, 2018 19:39
Great little function to download a javascript object as a JSON file.
// Great little function to download a javascript object as a JSON file. Found here:
// https://stackoverflow.com/questions/19721439/download-json-object-as-a-file-from-browser
function downloadObjectAsJson(exportObj, exportName){
var dataStr = "data:text/json;charset=utf-8," + encodeURIComponent(JSON.stringify(exportObj));
var downloadAnchorNode = document.createElement('a');
downloadAnchorNode.setAttribute("href", dataStr);
downloadAnchorNode.setAttribute("download", exportName + ".json");
downloadAnchorNode.click();
downloadAnchorNode.remove();
@colonelpopcorn
colonelpopcorn / windows-identity-add.sh
Created November 29, 2016 13:47
Loops through an array of paths to ssh keys and adds them to the agent in a git bash for windows session. Still requires passwords.
#declares an array of keys to loop through and add to the ssh-agent, run before a git bash session on windwows.
#bin/sh
declare -a keys=("/c/users/jonathan/path/to/key" "/c/users/jonathan/path/to/other/key")
eval $(ssh-agent -s)
for i in "${keys[@]}"; do
ssh-add "$i"
done
@colonelpopcorn
colonelpopcorn / background.cmd
Created June 4, 2016 22:08
Command script to change login screen background on Windows 7
@echo off
SET SOURCE=%~dp0%
SET DESTINATION=C:\Windows\System32\oobe\info\backgrounds
REG ADD HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Authentication\LogonUI\Background /f /v OEMBackground /t REG_DWord /d 0x00000001
IF NOT EXIST "%DESTINATION%" MKDIR "%DESTINATION%"
copy %SOURCE%\backgroundDefault.jpg %DESTINATION%
pause
something