Skip to content

Instantly share code, notes, and snippets.

View alexdiliberto's full-sized avatar

Alex DiLiberto alexdiliberto

View GitHub Profile
@alexdiliberto
alexdiliberto / get_random_bytes.js
Created February 25, 2016 16:57
Get random bytes in Javascript (Browser/Node)
let getRandomBytes = (
(typeof self !== 'undefined' && (self.crypto || self.msCrypto))
? function() { // Browsers
var crypto = (self.crypto || self.msCrypto), QUOTA = 65536;
return function(n) {
var a = new Uint8Array(n);
for (var i = 0; i < n; i += QUOTA) {
crypto.getRandomValues(a.subarray(i, i + Math.min(n - i, QUOTA)));
}
return a;
@alexdiliberto
alexdiliberto / ember-list-all-routes.js
Last active April 21, 2023 08:59
List all Ember route paths. (Just paste this in the console of your favorite Ember app)
// NOTE: `AppName` is simply your PascalCase application name (`modulePrefix` key from `../config/environment.js`)
window.AppName.__container__.lookup('service:router')._router._routerMicrolib.recognizer.names;
@alexdiliberto
alexdiliberto / UpdateChocolatey.bat
Created April 18, 2023 20:17 — forked from lowleveldesign/UpdateChocolatey.bat
Scripts to automatically update all Chocolatey packages installed on your system
@echo off
powershell -NoProfile -ExecutionPolicy ByPass -File "%~d0%~p0%~n0.ps1"
@alexdiliberto
alexdiliberto / controllers.application.js
Last active March 9, 2023 01:31
Ember's Route Hook Order
import Ember from 'ember';
export default Ember.Controller.extend({
appName: `Ember's Route Hook Order`,
actions: {
clearLog() {
Ember.$('.log-item').remove();
}
}
@alexdiliberto
alexdiliberto / evented_service.js
Created October 20, 2015 00:12
Pattern for dispatching events from Services in Ember
// app/services/locale.js
export default Ember.Service.extend(Ember.Evented, {
init() {
this._super(...arguments);
// initialize locales from localStorage (or URL string)
},
currentLocale() {
return ...;
@alexdiliberto
alexdiliberto / .eslintrc.js
Last active August 31, 2022 23:20
Integrate Prettier with Ember
/*
'plugin:prettier/recommended' does the following:
extends: ['prettier'],
plugins: ['prettier'],
rules: {
'prettier/prettier': 'error'
}
*/
module.exports = {
import Controller from '@ember/controller';
export default class ApplicationController extends Controller {
appName = 'Ember Twiddle';
}
@alexdiliberto
alexdiliberto / full-width-image.hbs
Created April 3, 2020 20:58
Full width image + Tailwind (marketing pages)
{{!-- https://github.com/embermap/emberconf2020-tailwind-css-best-practices --}}
<article class="flex flex-col items-center px-4 mt-4">
<h1 class="w-full max-w-md mx-auto text-xl font-bold">
Lowest Common Ancestor
</h1>
<p class="max-w-md mt-4 text-xs font-medium text-gray-600">
One of the biggest challenges when writing a JavaScript application is keeping multiple parts of the interface in sync. A user interaction in one part of the interface often affects data in another. If not managed well, this data can end up in multiple places, but with inconsistent values.
</p>
@alexdiliberto
alexdiliberto / random-walk.html
Created January 25, 2021 02:23 — forked from hacknightly/random-walk.html
A Random Walk in JavaScript
<html>
<head>
<style>
body {
padding: 0;
margin: 0;
height: 100%;
width: 100%;
display: flex;
justify-content: center;