Skip to content

Instantly share code, notes, and snippets.

View jeanbza's full-sized avatar
🐘

Jean Barkhuysen jeanbza

🐘
View GitHub Profile
@jeanbza
jeanbza / automate_2048.md
Last active July 9, 2023 03:42
Automate 2048

So I got to playing 2048 a decent amount, and starting getting the feeling that there was a 'pattern' that would win this game for me. Perhaps you've had the same thought! As a result, I wrote a little snippet of code that that cycles throw the keys Up, Right, Down, Left (feel free to create your own pattern).

Copy and paste this into your Chrome/Firefox console to automate 2048!

Firefox

function pressKey(i) {
  var evt = document.createEvent("KeyboardEvent");
  evt.initKeyEvent ("keydown", true, true, window, 0, 0, 0, 0, 37+i%4, 37+i%4);
 document.dispatchEvent(evt);
@jeanbza
jeanbza / log.go
Last active August 29, 2015 14:00 — forked from cespare/log.go
import (
"time"
"net/http"
"io"
"fmt"
"strings"
)
const apacheFormatPattern = "%s - - [%s] \"%s %s %s\" %d %d %.4f\n"
@jeanbza
jeanbza / automate_will_you_drown.md
Last active August 29, 2015 14:00
Automate 'Will You Drown?'

Automating the small text game Will You Drown? (http://game.notch.net/drowning/#) is pretty easy:

window.setInterval(function(){
    for (i = 0; i < document.getElementsByTagName("a").length; i++) {
        document.getElementById(document.getElementsByTagName("a")[i].id).click();
    }
}, 500);
@jeanbza
jeanbza / Glog weirdness.md
Last active August 29, 2015 14:00
Glog weirdness (log_dir)

See below a basic glog usage example run in bash on a mac:

// (temp.go)

package main

import (
    "log"
    "github.com/golang/glog"
@jeanbza
jeanbza / gostructfunctions.go
Created June 9, 2014 02:26
Printing the functions of a Go struct
package main
import (
"fmt"
"reflect"
)
type A struct {
}
@jeanbza
jeanbza / vector.js
Created November 7, 2014 05:05
Vector javascript kata
// http://www.codewars.com/kata/vector-class/train/javascript
var Vector = function(a) {
return {
get: function(key) {
return a[key];
},
getAll: function() {
return a;
},
@jeanbza
jeanbza / jsp.md
Created January 28, 2015 15:30
Something about JSP is just not pretty..

Handlebars:

{{#if people}}
  ... output person's info here...
{{/if}}

JSP (java templating):

@jeanbza
jeanbza / starting_rspec.md
Last active August 29, 2015 14:19
Starting with rspec

Writing tests with rspec

  1. Rspec basic layout:
/my_integration_tests
  Gemfile
  /spec
    spec_helper.rb
    /features
simulators
|
|-- endpoint_foo_simulator.rb
| ---> GET/POST/PUT/PATCH /actual/endpoint/we/are/simulating
| ---> GET /requests (list of requests)
| ---> POST /response (change the response)
| ---> GET /response (html page that shows current response, and has a single form - which
| allow you to change the response - that points to POST /response)
|-- endpoint_bar_simulator.rb
| ---> GET/POST/PUT/PATCH /actual/endpoint/we/are/simulating
  1. Enter vi edit mode for multiple files:
$ ○ → vi webapps/*.xml
5 files to edit
  1. See all files you're editing: :ls
  2. Search and replace across all files: :argdo %s/old-foo/new-foo/ge