Skip to content

Instantly share code, notes, and snippets.

# Reset
Color_Off='\e[0m' # Text Reset
# Regular Colors
Black='\e[0;30m' # Black
Red='\e[0;31m' # Red
Green='\e[0;32m' # Green
Yellow='\e[0;33m' # Yellow
Blue='\e[0;34m' # Blue
Purple='\e[0;35m' # Purple
@joeytrapp
joeytrapp / gist:65890927942b7725e60d
Created August 11, 2014 16:48
Example of pretender fixtures that can be run in the browser and queried against with jQuery.
// visit localhost:3000/test/demo.html
// run this snippet from chrome dev tools sources panel
agent = new Agent();
userIds = agent.makeIds('users', 2);
agent.group('users', function() {
this.fixture(userIds[1], { first: 'Joey', last: 'Trapp' });
this.fixture(userIds[2], { first: 'Lee', last: 'Forkenbrock' });
});
@joeytrapp
joeytrapp / application_controller.js
Last active August 29, 2015 14:05
Ember Notifications
App.ApplicationController = Em.Controller.extend({
notifictions: Blocks.Notifications.create(),
actions: {
notify: function() {
if (typeof obj === 'string') {
obj = { message: obj };
}
this.get('notifications').createNotification(obj);
},
@joeytrapp
joeytrapp / index.html
Last active August 29, 2015 14:05
z-index demo
<!DOCTYPE html>
<html>
<head>
<title>z-index test</title>
<style>
body {
z-index: 100;
background: white;
}
div {
@joeytrapp
joeytrapp / package.json
Created September 19, 2014 20:42
Load and link local modules in vendor/ as items in node_modules/
{
"name": "name",
"version": "0.0.1",
"description": "desc",
"main": "index.js",
"scripts": {
"test": "make test",
"preinstall": "find vendor -type d -maxdepth 1 | tail -n 2 | cut -c8- | xargs -L 1 -I {} rm -f node_modules/{}",
"postinstall": "find vendor -type d -maxdepth 1 | tail -n 2 | cut -c8- | xargs -L 1 -I {} sh -c 'ln -s \"$(pwd)/vendor/{}\" node_modules/{}; cd vendor/{} && npm install'"
},
class App extends React.Component {
constructor() {
super();
this.state = { showPicker: true };
}
componentDidUpdate() {
console.log(document.querySelectorAll(".pika-single"));
}
@joeytrapp
joeytrapp / FileBtn.re
Created April 10, 2019 17:54
ReasonReact 0.7.0 ref example
[@react.component]
let make = (~className="", ~onSelect, ~children) => {
let fileInputRef: ReactDOMRe.Ref.currentDomRef =
React.useRef(None->Js.Nullable.fromOption);
let key = React.useRef(1);
let handleInputChange =
React.useCallback0(event => {
let files = ReactEvent.Form.target(event)##files;
@joeytrapp
joeytrapp / phoenix_test_redirect_missing_req_headers.exs
Last active September 6, 2024 23:44
Demonstrate that manually set request headers are not present in redirect/navigate requests
Mix.install(
[
{:phoenix_playground, "~> 0.1.6"},
{:phoenix_test, "~> 0.3.2"}
],
config: [
phoenix_test: [endpoint: Demo.Endpoint],
phoenix_playground: [
{Demo.Endpoint,
[
@joeytrapp
joeytrapp / aoc_1.erl
Last active December 9, 2024 06:57
Advent of Code 2024 Day 1 Part 1 and Part 2
-module(aoc).
-export([main/1]).
-import(file, [read_file/1]).
-import(lists, [unzip/1, map/2, zip/2, sort/1, foldl/3, filter/2, sum/1]).
-import(maps, [get/3, update_with/4]).
-import(string, [is_empty/1, split/3, trim/1]).
main([Path]) ->
@joeytrapp
joeytrapp / aoc_2.erl
Last active December 9, 2024 06:58
Advent of Code 2024 Day 2 Part 1 and Part 2
-module(aoc).
-export([main/1]).
main([Path]) ->
{ok, Data} = parse(Path),
io:format("Safe: ~p~n", [lists:sum(lists:map(fun is_safe/1, Data))]),
io:format("Dampened: ~p~n", [lists:sum(lists:map(fun is_less_safe/1, Data))]),
erlang:halt(0).