Skip to content

Instantly share code, notes, and snippets.

@csmr
csmr / get-rust-repl-on-stretch.sh
Created October 2, 2018 16:24
Copypaste into shell to quickly get rust repl in debian stretch
sudo apt remove rustc '^libstd-rust*'
curl https://sh.rustup.rs -sSf | sh
# [ hit enter for default]
source $HOME/.cargo/env
rustc --version
cargo --version
cargo install evcxr_repl
evcxr
@ljharb
ljharb / array_iteration_thoughts.md
Last active April 29, 2024 17:13
Array iteration methods summarized

Array Iteration

https://gist.github.com/ljharb/58faf1cfcb4e6808f74aae4ef7944cff

While attempting to explain JavaScript's reduce method on arrays, conceptually, I came up with the following - hopefully it's helpful; happy to tweak it if anyone has suggestions.

Intro

JavaScript Arrays have lots of built in methods on their prototype. Some of them mutate - ie, they change the underlying array in-place. Luckily, most of them do not - they instead return an entirely distinct array. Since arrays are conceptually a contiguous list of items, it helps code clarity and maintainability a lot to be able to operate on them in a "functional" way. (I'll also insist on referring to an array as a "list" - although in some languages, List is a native data type, in JS and this post, I'm referring to the concept. Everywhere I use the word "list" you can assume I'm talking about a JS Array) This means, to perform a single operation on the list as a whole ("atomically"), and to return a new list - thus making it mu

@mattd
mattd / proxy.js
Last active December 19, 2015 16:48
Stupid simple proxy from your dev environment to any arbitrary remove server.
// Usage from some other file:
//
// var app = require('./proxy')({proxyUrl: '//your-remote.com', proxyBase: '/api'})
var path = require('path'),
request = require('request'),
express = require('express'),
app = express();
app.use(express.logger('dev'));
@marcedwards
marcedwards / high-dpi-media.css
Last active November 19, 2023 12:56
A CSS media query that captures almost all high DPI aware devices.
/* ---------------------------------------------------------- */
/* */
/* A media query that captures: */
/* */
/* - Retina iOS devices */
/* - Retina Macs running Safari */
/* - High DPI Windows PCs running IE 8 and above */
/* - Low DPI Windows PCs running IE, zoomed in */
/* - Low DPI Windows PCs and Macs running Firefox, zoomed in */
/* - Android hdpi devices and above */
@amscotti
amscotti / sinatra_linkedin.rb
Created November 26, 2011 04:42
LinkedIn authentication with Sinatra
require "rubygems"
require "haml"
require "sinatra"
require "linkedin"
enable :sessions
helpers do
def login?
if session[:atoken].nil?