Skip to content

Instantly share code, notes, and snippets.

View z5h's full-sized avatar
🕳️

Mark Bolusmjak z5h

🕳️
View GitHub Profile
@z5h
z5h / join-on
Last active August 29, 2015 14:05
does a join on 2 files based on 1st capture of regex. e.g.: join-on Gemfile "gem '([^']*)'" Gemfile.lock " *([^ ]*)"
#!/usr/bin/env ruby
# example use: join-on Gemfile "gem '([^']*)'" Gemfile.lock " *([^ ]*)"
file1, cap1, file2, cap2 = *ARGV
r1 = Regexp.new(cap1)
r2 = Regexp.new(cap2)
line_match_number = []
n = 0
max_len = 0
File.open(file1).each do |line|
@z5h
z5h / update.js
Last active August 29, 2015 14:13
Get the result of updating a Javascript object while treating it as immutable.
/**
* Get the result of updating `obj` with `props`, while treating `obj`
* as immutable.
*/
var update = function(obj, props){
var keys = Object.keys(props),
key,
changed = false,
i;

Keybase proof

I hereby claim:

  • I am z5h on github.
  • I am bolusmjak (https://keybase.io/bolusmjak) on keybase.
  • I have a public key whose fingerprint is RETU RN T HIS. PGP. GET_ FING ERPR INT( ); }

To claim this, I am signing this object:

@z5h
z5h / Swap.elm
Created July 24, 2015 17:23
Elm rendering focus loss
import Html exposing (..)
import Html.Attributes exposing (..)
import Html.Events exposing (..)
type Action
= NoOp
| EditEntry Entry String
type alias Entry =
#lang scheme
(define grammar1
'((T (R))
(T ("a" T "c"))
(R ())
(R (R "b" R))))
(define grammar2
'((T (R))
module TimeApp ( start, Config, App ) where
{-| This module helps you start your application in a typical Elm workflow.
It assumes you are following [the Elm Architecture][arch] and using
[elm-effects][]. From there it will wire everything up for you!
**Be sure to [read the Elm Architecture tutorial][arch] to learn how this all
works!**
[arch]: https://github.com/evancz/elm-architecture-tutorial
[elm-effects]: http://package.elm-lang.org/packages/evancz/elm-effects/latest
import Stopwatch
import Html exposing (..)
import Html.App as App
import Html.Attributes exposing (..)
import Html.Events exposing (..)
main: Program Never
main =
App.program
{ init = init
@z5h
z5h / StickierDiv.jsx
Last active November 17, 2016 13:46
sticky header div react js
/** @jsx React.DOM */
"use strict";
var util = {
// findPos() by quirksmode.org
// Finds the absolute position of an element on a page
findPos: function (obj) {
var curleft = 0,
curtop = 0;
@z5h
z5h / ycombinator.clj
Created March 6, 2013 20:25
Applicative-Order Y Combinator (Clojure Version)
; Stumbling towards Y (Clojure Version)
;
; (this tutorial can be cut & pasted into your IDE / editor)
;
; The applicative-order Y combinator is a function that allows one to create a
; recursive function without using define.
; This may seem strange, because usually a recursive function has to call
; itself, and thus relies on itself having been defined.
;
; Regardless, here we will stumble towards the implementation of the Y combinator.