Skip to content

Instantly share code, notes, and snippets.

View dahjelle's full-sized avatar

David Alan Hjelle dahjelle

View GitHub Profile
@dahjelle
dahjelle / index.markdown
Created April 6, 2017 16:01
Tips For Processing Large Files

Tips for Processing Large Files

Extract the First 100 Lines

head -n 100 filename.txt > smallfile.txt

Extract the Last 100 Lines

tail -n 100 filename.txt > smallfile.txt
@dahjelle
dahjelle / pre-commit.sh
Created July 13, 2016 16:48
Pre-commit hook for eslint, linting *only* staged changes.
#!/bin/bash
for file in $(git diff --cached --name-only | grep -E '\.(js|jsx)$')
do
git show ":$file" | node_modules/.bin/eslint --stdin --stdin-filename "$file" # we only want to lint the staged changes, not any un-staged changes
if [ $? -ne 0 ]; then
echo "ESLint failed on staged file '$file'. Please check your code and try again. You can run ESLint manually via npm run eslint."
exit 1 # exit with failure status
fi
done
@dahjelle
dahjelle / couch.log
Created January 30, 2015 12:48
CouchDB 1.6.1 "Verify Installation" Error on CentOS 7
$ cat /var/log/couchdb/couch.log
[Fri, 30 Jan 2015 12:47:35 GMT] [info] [<0.31.0>] Apache CouchDB has started on http://127.0.0.1:5984/
[Fri, 30 Jan 2015 12:47:41 GMT] [info] [<0.110.0>] 192.168.1.145 - - DELETE /test_suite_db/ 200
[Fri, 30 Jan 2015 12:47:41 GMT] [info] [<0.110.0>] 192.168.1.145 - - PUT /test_suite_db/ 201
[Fri, 30 Jan 2015 12:47:41 GMT] [info] [<0.110.0>] 192.168.1.145 - - PUT /test_suite_db/abd79b2753f1a4148bbc4c98d602e591 201
[Fri, 30 Jan 2015 12:47:41 GMT] [info] [<0.110.0>] 192.168.1.145 - - PUT /test_suite_db/abd79b2753f1a4148bbc4c98d602e591 201
[Fri, 30 Jan 2015 12:47:41 GMT] [info] [<0.110.0>] 192.168.1.145 - - DELETE /test_suite_db/abd79b2753f1a4148bbc4c98d602e591?rev=2-c5242a69558bf0c24dda59b585d1a52b 200
[Fri, 30 Jan 2015 12:47:41 GMT] [info] [<0.110.0>] 192.168.1.145 - - GET /test_suite_db/undefined 404
[Fri, 30 Jan 2015 12:47:41 GMT] [info] [<0.110.0>] 192.168.1.145 - - PUT /test_suite_db/abd79b2753f1a4148bbc4c98d602e342 201
[Fri, 30 Jan 2015 12:47:41 GMT] [info] [<0.110.0>] 192.
@dahjelle
dahjelle / server.js
Created January 26, 2015 18:57
Attempting cluster-based graceful restarts in Hapi
var Hapi = require('hapi');
var PORT = process.env.PORT || 3000;
var server = new Hapi.Server();
server.connection({
port: PORT
});
server.route({
@dahjelle
dahjelle / Array Exercises (PHP).markdown
Last active November 5, 2023 05:17
Array Exercises (PHP)

Array Exercises (PHP)

Questions

  1. If you have an array $a = array( 0, 1, 2, 3, 4 );, how do you extract the value 3 from the array?

  2. If you have an array $a = array( "zero"=>0, "one"=>1, "two"=>2, "three"=>3, "four"=>4 );, how do you extract the value 3 from the array?

  3. If you have the following array, how do you extract the value 3 from the array?

@dahjelle
dahjelle / Git Up and Git Down.markdown
Last active October 3, 2016 18:23
`git-up` and `git-down`: A Rebase-centric Git Workflow

In my git development, I have an origin repository with a single branch that reflects our currently-deployed production code, and my own repository on my own machine. I develop features and bugfixes in their own branches. With help from several places around the internet (which I'm afraid I've forgotten), I've developed these git aliases to help smooth out my workflow.

[alias]
    sync = "!f() { echo Syncing this branch with master && git checkout master && git pull --ff-only && git checkout - && git rebase --committer-date-is-author-date --preserve-merges master; }; f"
    release = "!f() { BRANCH=$(git rev-parse --abbrev-ref HEAD); FF=\"--no-ff\"; if [ $(git log --pretty=oneline master..HEAD | wc -l) -eq "1" ]; then FF="--ff"; fi; echo \"Sending changes from '$BRANCH' to origin. $FF\"; git checkout master && git merge $FF $BRANCH && ssh ORIGIN_SERVER 'cd ORIGIN_DIR && git pull --ff-only MY_REMOTE master'; }; f"

git sync will grab all changes from origin into master and then rebase your

@dahjelle
dahjelle / Testing JSON APIs from my editor.markdown
Created April 16, 2014 21:26
Testing JSON APIs from my editor

I was working on a JSON API (for IconCMO) and realized that it'd be nice to be able to see the output of the API in my editor. In particular, I not only wanted the JSON output pretty-printed, but also wanted to highlight a few specific keys of the output, as that's what my code was focusing on.

Most editors let you execute shell commands in one way or another, and display their output. Here's the command I used (the URL is local-only) and its output:

OUTPUT=$(curl --request POST --data '{"Auth": {"Phone": "5555555555", "Username": "JoePUser", "Password": "password"}, "Request": {"Module": "payroll", "Section": "payment_method_form"} }' --header 'Content-type:application/json' --silent https://david.iconcmo.com/api/); echo $OUTPUT | jq '.payment_method_form.test'; echo $OUTPUT
{
@dahjelle
dahjelle / Patch Fedora 18 OpenSSL for Heartbleed, CVE-2014-0160.markdown
Last active February 17, 2016 18:01
Patch Fedora 18 OpenSSL for Heartbleed, CVE-2014-0160

To update Fedora 18 against Heartbleed, you'll need to roll your own RPMs since 18 is no longer supported. (Consider CentOS?)

Here's what worked for me, based heavily on the CentOS guide on rebuilding RPMs. Your mileage may vary. I did have things like gcc and make already installed.

$ sudo yum install rpm-build
$ mkdir -p ~/rpmbuild/{BUILD,RPMS,SOURCES,SPECS,SRPMS}
$ echo '%_topdir %(echo $HOME)/rpmbuild' > ~/.rpmmacros
$ cd /tmp
$ wget http://mirrors.kernel.org/fedora/updates/18/SRPMS/openssl-1.0.1e-37.fc18.src.rpm
@dahjelle
dahjelle / Function.before.markdown
Last active August 29, 2015 13:57
Add Before Advice (aspect-oriented) to a Function (using Sugar.js)

Assuming Sugar.js is installed, you can run this to add a before method to all functions.

Function.extend( {
    before: function( func ) {
        // TODO: could add ability to output function name (via this.toString() and a regex)
        // TODO: could add ability to modify arguments before getting passed to function
        var that = this;
        return function() {
 var args = Array.create( arguments );