Skip to content

Instantly share code, notes, and snippets.

@daniel-nelson
daniel-nelson / pre-push
Last active February 19, 2021 18:01
Confirm before pushing to production repositories. Place in .git/hooks/ and make executable
#!/bin/bash
if [[ "$1" =~ "production" ]]; then
read -a array
pushed_ref=${array[1]}
remote_ref=${array[3]}
echo
echo "# Commits:"
git log --oneline $remote_ref...$pushed_ref
module ModuleName
include OtherModules
delegate :some_method, to: :some_object
module ClassMethods
def class_method
end
end
#
# my solution to ListsAndRecursion-6 of Programming Elixir 1.6
#
defmodule MyList do
def flatten([]) do
[]
end
def flatten([head | tail]) when is_list(head) do
flatten(head) ++ flatten(tail)
require 'fileutils'
type_map = {
jpeg: 'Photos',
JPEG: 'Photos',
jpg: 'Photos',
JPG: 'Photos',
png: 'PNGs',
PNG: 'PNGs',
mov: 'Videos',
.fa-events-icons-failed {
&.icon {
&::before {
display: none;
}
&::after {
@extend .din-bold;
}
}
Angular:
dashboard.module.es6 // Defines the DashboardApp
dashboard.controller.es6
order_queue.module.es6 // Defines the OrderQueueApp
order_queue.controller.es6
modal.directive.js // A general purpose directive for displaying modals. Modal html is loaded from templates
Angular Templates:
dashboard_order_info_modal.html // Renders order_info_details
order_queue_info_modal.html // Also renders order_info_details
struct order *orders;
// ...
// *orders is assigned to point to a block of memory returned by ALLOC_N (from ruby.h)
// ...
// Data in *orders is fine here
struct winning_order winners[winners_length];
// Data in *orders is corrupt here (see below)
Subset of data pre and post local declaration of "winners" variable:
Evernote asks me to select a plan too often. I understand that Evernote wants to prompt me to upgrade in case my needs have changed; however, prompting every week or more is excessive. This week, it prompted me two days in a row.
I could accept frequent prompts when I go to the Evernote application, but the actual behavior is that it starts bouncing the Evernote icon in the doc when I am using other applications (I leave many apps, including Evernote, open most of the time), which interrupts work I am doing.
After adding pubsub (using Pubnub.com) to our application, our headless specs were straight up breaking. Solved by creating a mock that we can trigger within the specs
Coffeescript required by application.js manifest:
class PubsubMock
subscribe: (obj) ->
@channels ||= {}
@channels[obj.channel] ||= []
@channels[obj.channel].push(obj.message)
@daniel-nelson
daniel-nelson / confirm.coffee
Created June 15, 2015 19:31
Bootstrap popover based confirm directive for Angularjs
# Usage:
# <div "ng-repeat"="comment in comments">
# <a class="remove" href="" "pj-confirm"="Really remove?" "popover-placement"="left"
# "on-confirm"="deleteComment" "callback-argument"="comment" "confirm-btn-label"="Yes" "cancel-btn-label"="No">Delete</a>
# </div>
#
# Dependencies:
# jQuery UI (for position function)
# Bootstrap CSS