Skip to content

Instantly share code, notes, and snippets.

@leonardreidy
leonardreidy / coffeescript-utils.sh
Created August 17, 2017 21:57
coffeescript-utils
# Walk the directory tree from the current folder and
# transpile the given coffeescript files to JS, placing
# them in the directory with the name outputDir
coffee --output outputDir --compile .
@leonardreidy
leonardreidy / git.md
Last active December 14, 2017 10:25
Git

Merge Conflicts

See code before either change (before change in both branches that now conflicts)

git diff --merge

Restoring

In Git there are many ways to revert/restore the codebase, chunk by chunk (verify), file by file, en masse, and so on. One way is simply to make the best of the checkout command! To illustrate, suppose you are working on a Rails project, and you are on branch development where you have put one of your existing serializers through a series of modifications. The word comes down that messing with the given serializer is causing problems for the other devs. You find a better way to

@leonardreidy
leonardreidy / python-housekeeping-utilities.py
Last active August 9, 2021 12:35
Python Housekeeping Utilities
import os
# For every file in the current directory, replace '.js' in the filename with an empty
# string if the file is not a directory
[os.rename(f, f.replace('.js', '')) for f in os.listdir('.') if not os.path.isdir(f)]
# For every file in every subdirectory of the target directory (targetDir), replace '.js' in the filename
# with an empty string if the file is not a directory
def renameDoubleBarrelledCoffeeScriptsIn(targetDir):
for root, subdirs, files in os.walk(targetDir):
@leonardreidy
leonardreidy / redux-and-react.js
Created May 24, 2017 17:03
Using React and Redux together - with annotations
// constants for serialisable actions
const INC = 'INCREMENT';
const DEC = 'DECREMENT';
// counter reducer
const counter = (state = 0, action) => {
switch(action.type){
case INC:
return state + 1;
case DEC:
// Implement Redux createStore function from scratch,
// with annotations
// Code by Dan Abramov, notes by my good self
const createStore = (reducer) => {
// declare a variable for state
// confined in scope to the block,
// statement or expression in which it
// is used
// store holds current state here
# A collection of generally useful Bash commands
# check storage device performance
dd if=/dev/sda1 of=/dev/null bs=1024k count=1024
/**
* A Basic JavaScript Library Pattern
* From Thomas Valentine and Jonathan Reid, JavaScript Programmers Reference
* Apress,2013, (p.130/289)
*/
(function() {
var window = this,
undefined;
@leonardreidy
leonardreidy / start-stop-xampp.sh
Last active December 5, 2016 13:13
Bash function for starting and stopping xampp from the command line on Ubuntu
# Bash function for starting and stopping xampp from the command line on Ubuntu
function xampp() {
# If the argument supplied to the function is --stop
if [[ $@ == "--stop" ]];
then
# stop the xampp/lampp services
sudo bash /opt/lampp/lampp stop
# If the argument supplied to the function is --start
elif [[ $@ == "--start" ]];
then
@leonardreidy
leonardreidy / analyse-startup-and-plot.bash
Created October 28, 2016 22:42
Analyse Ubuntu startup, plot, and output to svg file
systemd-analyze plot > sequence.svg
@leonardreidy
leonardreidy / change-file-endings-from-txt-to-md.py
Created October 28, 2016 16:28
Change all file endings in the current folder to .md if they are currently ending in .txt
import os,sys
folder = os.getcwd();
for filename in os.listdir(folder):
infilename = os.path.join(folder,filename)
if not os.path.isfile(infilename): continue
oldbase = os.path.splitext(filename)
newname = infilename.replace('.txt', '.md')
output = os.rename(infilename, newname)