Skip to content

Instantly share code, notes, and snippets.

View jashmenn's full-sized avatar

Nate Murray jashmenn

View GitHub Profile
@jashmenn
jashmenn / vending-machine-smart-contract.js
Last active December 13, 2020 13:16
Pseudocode for a vending machine "smart contract" in JavaScript
/**
* A pseudo VendingMachine "smart contract" in JavaScript
*
* See: https://newline.co
**/
class VendingMachine {
constructor() {
this.price = 50; // 50 cents for any soda
this.balance = 0; // number of cents paid so far
this.selection = null; // name of selected drink
{
"config": {
"chainId": 101,
"homesteadBlock": 0,
"eip155Block": 0,
"eip158Block": 0
},
"alloc" : {},
"coinbase" : "0x0000000000000000000000000000000000000000",
@jashmenn
jashmenn / git-selective-merge.md
Created April 21, 2017 16:16 — forked from katylava/git-selective-merge.md
git selective merge

Example: You have a branch refactor that is quite different from master. You can't merge all of the commits, or even every hunk in any single commit or master will break, but you have made a lot of improvements there that you would like to bring over to master.

Note: This will not preserve the original change authors. Only use if necessary, or if you don't mind losing that information, or if you are only merging your own work.

On master:

> git co -b temp
@jashmenn
jashmenn / pr.md
Created March 9, 2017 20:21 — forked from piscisaureus/pr.md
Checkout github pull requests locally

Locate the section for your github remote in the .git/config file. It looks like this:

[remote "origin"]
	fetch = +refs/heads/*:refs/remotes/origin/*
	url = git@github.com:joyent/node.git

Now add the line fetch = +refs/pull/*/head:refs/remotes/origin/pr/* to this section. Obviously, change the github url to match your project's URL. It ends up looking like this:

@jashmenn
jashmenn / github-operator-mono-dark.css
Last active March 9, 2018 19:58
Stylish Chrome Extension for Github Operator Mono Dark Theme
.markdown-body .highlight pre,
table.highlight,
.blob-code-inner {
font-family: "Operator Mono";
font-weight: 400;
line-height: 1.5em;
font-size: 14px;
}
.markdown-body .highlight pre,
table.highlight {
@jashmenn
jashmenn / ng-book-rc.4.diff
Created July 1, 2016 00:40
ng-book 2 code diff between rc.2 and rc.4 - https://www.ng-book.com/2
diff --git a/manuscript/code/advanced_components/app/ts/app.ts b/manuscript/code/advanced_components/app/ts/app.ts
index 6db6693..830beb2 100644
--- a/manuscript/code/advanced_components/app/ts/app.ts
+++ b/manuscript/code/advanced_components/app/ts/app.ts
@@ -13,10 +13,10 @@ import {
import { bootstrap } from '@angular/platform-browser-dynamic';
import {
ROUTER_DIRECTIVES,
- ROUTER_PROVIDERS,
- RouteDefinition,
#!/bin/bash -x
#
# Angular 2.0.0-rc.1 renamed a bunch of modules. This script can help you do a
# little bit of the dirty work for renaming those modules.
#
# As a bonus, this script will try to fix your template-local variables
# e.g. *ngFor="#thread of threads" becomes -> *ngFor="let thread of threads"
#
# 🦁 by Nate Murray nate@fullstack.io // https://ng-book.com/2
#
@jashmenn
jashmenn / self-eq-this-vs-bind.md
Last active September 6, 2022 23:11
Javascript var self = this; vs. .bind

The Problem

In Javascript this is bound in unexpected ways. Functions, in particular, create a new 'this' and so when you want to keep a reference to an "outer" object you sometimes see the pattern:

var self = this;

as in:

var self = this;
@jashmenn
jashmenn / RxPipe.ts
Created August 21, 2015 00:24
RxJS Support for Angular 2 Async Pipes - (angular-2.0.0.alpha-35 and above)
/// <reference path="../../typings/app.d.ts" />
//
// Creates a pipe suitable for a RxJS observable:
//
// @View({
// template: '{{ someObservable | rx}}'
// pipes: [RxPipe]
// })
//
// Originally written by @gdi2290 but updated for 2.0.0.alpha-35 and use AsyncPipe
;; source: http://steve.yegge.googlepages.com/my-dot-emacs-file
(defun rename-file-and-buffer (new-name)
"Renames both current buffer and file it's visiting to NEW-NAME."
(interactive "sNew name: ")
(let ((name (buffer-name))
(filename (buffer-file-name)))
(if (not filename)
(message "Buffer '%s' is not visiting a file!" name)
(if (get-buffer new-name)
(message "A buffer named '%s' already exists!" new-name)