Skip to content

Instantly share code, notes, and snippets.

David Alan Hjelle dahjelle

Block or report user

Report or block dahjelle

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@dahjelle
dahjelle / index.markdown
Created Apr 6, 2017
Tips For Processing Large Files
View index.markdown

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 Jul 13, 2016
Pre-commit hook for eslint, linting *only* staged changes.
View pre-commit.sh
#!/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 Jan 30, 2015
CouchDB 1.6.1 "Verify Installation" Error on CentOS 7
View couch.log
$ 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 Jan 26, 2015
Attempting cluster-based graceful restarts in Hapi
View server.js
var Hapi = require('hapi');
var PORT = process.env.PORT || 3000;
var server = new Hapi.Server();
server.connection({
port: PORT
});
server.route({
View Array Exercises (PHP).markdown

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 Oct 3, 2016
`git-up` and `git-down`: A Rebase-centric Git Workflow
View Git Up and Git Down.markdown

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

View Testing JSON APIs from my editor.markdown

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 Feb 17, 2016
Patch Fedora 18 OpenSSL for Heartbleed, CVE-2014-0160
View Patch Fedora 18 OpenSSL for Heartbleed, CVE-2014-0160.markdown

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 Aug 29, 2015
Add Before Advice (aspect-oriented) to a Function (using Sugar.js)
View Function.before.markdown

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 );
You can’t perform that action at this time.