Skip to content

Instantly share code, notes, and snippets.

View gist:96162bb24c242682dc77f29c16f67dd8
# Host Database
# localhost is used to configure the loopback interface
# when the system is booting. Do not change this entry.
## localhost broadcasthost
::1 localhost
motylwg / primesStreamExample.scala
Created Jun 26, 2013
Sieve of Eratosthenes using Scala streams.
View primesStreamExample.scala
def sieve(s: Stream[Int]): Stream[Int] =
s.head #:: sieve(s.tail filter(_ % s.head != 0))
val primes = sieve(Stream.from(2))
fperez / ProgrammaticNotebook.ipynb
Last active Dec 3, 2020
Creating an IPython Notebook programatically
View ProgrammaticNotebook.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
archisgore /
Last active Feb 17, 2021
NPM/Node.js code injection attack

NPM/Node.js recently had a clever, yet simple, code injection attack using "dependency confusion" as the vulnerability. I describe the attack as conducted (simulated, really), and a systemic solution Polyverse has been building for the past two years designed to solve specifically this problem.

A recap of the attack, for baseline:

Node dependencies are specified by name and version but not address/location, i.e., {“sorter”: “1.0”, “binary-search”: “2.0”, “polyverse-billing”: 1.0}.

Notice the last one? It’s intended to be Polyverse internal and contains our proprietary (and sensitive) billing code. Obviously it does not exist on, the public upstream node package repository. It instead comes from a private repository hosted by Polyverse.

In a Sequence Diagram, this is how the flow worked before the attack. Pretty straight-forward.

richard-flosi /
Created Sep 26, 2012
Bottle with Cross-origin resource sharing (CORS)
Example of setting up CORS with
from bottle import Bottle, request, response, run
app = Bottle()
def enable_cors():
gretingz /
Last active Mar 24, 2021
Proving that 1 + 1 = 2 in Rust

Proving that 1 + 1 = 2 in Rust

The fact that 1 + 1 is equal to 2 is one of those things that is so obvious it may be hard to justify why. Fortunately mathematicians have devised a way of formalizing arithmetic and subsequently proving that 1 + 1 = 2. Natural numbers are based on the Peano axioms. They are a set of simple rules that define (along with a formal system) what natural numbers are. So in order to prove 1 + 1 = 2 in Rust we first need a formal system capable of handling logic. The formal system that we'll be using is not some random crate, but Rust's type system itself! We will not have any runtime code, instead the type checker will do all the work for us.

Implementing the Peano axioms

First let's go trough the Peano axioms. The first axiom is that "Zero is a natural number". Basically what it says is that zero exists. In order to express that in the type system, we just write:

RaVbaker /
Created Mar 30, 2012
[HOWTO] Rewrite all urls to one index.php in Apache

Redirect All Requests To Index.php Using .htaccess

In one of my pet projects, I redirect all requests to index.php, which then decides what to do with it:

Simple Example

This snippet in your .htaccess will ensure that all requests for files and folders that does not exists will be redirected to index.php:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
tylerneylon / learn.lua
Last active Apr 18, 2021
Learn Lua quickly with this short yet comprehensive and friendly script. It's written as both an introduction and a quick reference. It's also a valid Lua script so you can verify that the code does what it says, and learn more by modifying and running this script in your Lua interpreter.
View learn.lua
-- Two dashes start a one-line comment.
Adding two ['s and ]'s makes it a
multi-line comment.
-- 1. Variables and flow control.
mattlewissf /
Last active Apr 18, 2021
Lightning Talk: Git add -p

git add -p is your friend

git add -p is basically "git add partial (or patch)"

Patch mode allows you to stage parts of a changed file, instead of the entire file. This allows you to make concise, well-crafted commits that make for an easier to read history. This feature can improve the quality of the commits. It also makes it easy to remove parts of the changes in a file that were only there for debugging purposes - prior to the commit without having to go back to the editor.

It allows you to see the changes (delta) to the code that you are trying to add, and lets you add them (or not) separately from each other using an interactive prompt. Here's how to use it:

from the command line, either use

  • git add -p
obstschale /
Last active May 3, 2021
An Octave introduction cheat sheet.