Skip to content

Instantly share code, notes, and snippets.

# got a huge ammount of help from https://stackoverflow.com/questions/11550153/determine-position-of-number-in-a-grid-of-numbers-centered-around-0-and-increasi
def sequence(i):
n = 2 * i - 1
return n * n
def layer(i):
return math.floor((math.sqrt(i) + 1) / 2)
def length(i):
@csuzw
csuzw / SpiralMemory.cs
Last active December 4, 2017 11:52
Advent of Code 2017 Day 3
int SpiralMemoryPartOne(int location)
{
if (location <= 1) return 0;
var ring = 1;
var max = 9;
while (max < location)
{
ring += 1;
max += (((ring + 1) * 2) - 2) * 4;
@lmakarov
lmakarov / lambda-basic-auth.js
Created August 30, 2017 19:15
Basic HTTP Authentication for CloudFront with Lambda@Edge
'use strict';
exports.handler = (event, context, callback) => {
// Get request and request headers
const request = event.Records[0].cf.request;
const headers = request.headers;
// Configure authentication
const authUser = 'user';
const authPass = 'pass';
@opera443399
opera443399 / python_UnicodeEncodeError.py
Last active October 18, 2023 16:47
export PYTHONIOENCODING=UTF-8
from:
http://chase-seibert.github.io/blog/2014/01/12/python-unicode-console-output.html
Print to the console in Python without UnicodeEncodeErrors 12 Jan 2014
I can't believe I just found out about this! If you use Python with unicode data, such as Django database records, you may have seen cases where you print a value to the console, and if you hit a record with an extended (non-ascii) character, your program crashes with the following:
Traceback (most recent call last):
File "foobar.py", line 792, in <module>
print value
UnicodeEncodeError: 'ascii' codec can't encode character u'\xa0' in position 20: ordinal not in range(128)
@iacovlev-pavel
iacovlev-pavel / geoserver-install.sh
Last active May 8, 2022 06:55
Install GeoServer on Ubuntu 18.04
#
apt-get install openjdk-8-jre
# PostgreSQL and PostGIS
apt-get install postgresql postgresql-contrib postgis postgresql-10-postgis-2.4
# Create "geoserver" database
sudo -u postgres createuser -P geoserver
sudo -u postgres createdb -O geoserver geoserver
sudo -u postgres psql -c "CREATE EXTENSION postgis; CREATE EXTENSION postgis_topology;" geoserver
@drhirsch
drhirsch / setup_gnuparallel.sh
Last active April 5, 2024 07:37
Install GNU Parallel on any system including Cygwin
#!/bin/bash
# useful for platforms such as Cygwin that don't currently have GNU Parallel in their repo.
# prerequisite: make
(
wd=$(mktemp -d)
wget -nc -P $wd ftp://ftp.gnu.org/gnu/parallel/parallel-latest.tar.bz2
cd $wd
function* runTimer(getState) {
while(yield take('START')) {
while(true) {
const {stop, tick} = yield race({
stop : take('STOP'),
tick : call(wait, ONE_SECOND);
})
if ( !stop ) {
yield put(actions.tick());
@t-mart
t-mart / netrw quick reference.md
Last active March 25, 2024 07:47
A quick reference for Vim's built-in netrw file selector.
Map Action
<F1> Causes Netrw to issue help
<cr> Netrw will enter the directory or read the file
<del> Netrw will attempt to remove the file/directory
- Makes Netrw go up one directory
a Toggles between normal display, hiding (suppress display of files matching g:netrw_list_hide) showing (display only files which match g:netrw_list_hide)
c Make browsing directory the current directory
C Setting the editing window
d Make a directory
@javisantana
javisantana / speed.sql
Created August 12, 2015 11:05
speed from a track table
WITH deltas as (
SELECT
st_distance(the_geom::geography, lag(the_geom::geography, 1) over(order by timestamp)) as ddist,
timestamp - lag(timestamp, 1) over(order by timestamp) as dt
from out_2 offset 1000
)
select avg(ddist/dt) as speed from deltas
@AustinDizzy
AustinDizzy / pre-commit
Created July 12, 2015 04:47
A pre-commit git hook that prompts you to automatically `gofmt` Go files staged to commit.
#!/bin/sh
# Modified 2015, Austin Dizzy
# Copyright 2012 The Go Authors. All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.
# git gofmt pre-commit hook
#
# To use, store as .git/hooks/pre-commit inside your repository and make sure
# it has execute permissions.