Skip to content

Instantly share code, notes, and snippets.

def get_persistence(array_of_numbers):
for current_number in array_of_numbers:
if current_result is None:
current_result = current_number
else:
current_result = current_result * current_number
if len(current_result) == 1:
@phalt
phalt / main.go
Created December 3, 2014 14:51
Simple HTTP API in Go
package main
import (
"github.com/gin-gonic/gin"
"database/sql"
"github.com/coopernurse/gorp"
_ "github.com/mattn/go-sqlite3"
"log"
"time"
"strconv"
# Change your settings file to this:
SECRET_KEY = os.environ.get('SECRET_KEY', 'MY_DEFAULT_KEY')
# Export the SECRET_KEY variable like in the terminal like so:
$ export SECRET_KEY=my_secret_key_here
@phalt
phalt / character.py
Created December 22, 2014 16:57
Get a character with a specific name from swapi.co
import swapi
get_character("name"):
for c in swapi.get_all("people"):
if c.name == name:
return c

Keybase proof

I hereby claim:

  • I am phalt on github.
  • I am phalt (https://keybase.io/phalt) on keybase.
  • I have a public key whose fingerprint is 138D 0025 66E7 B92D A195 4591 7A5E E47C 51C0 E3BA

To claim this, I am signing this object:

@phalt
phalt / reverse.py
Last active March 8, 2017 10:41
0(n) runtime string reverse
# 0(n) runtime
# Only needs to move up to half the way of the list in order to shuffle things around.
# Something fast would be a merge sort with a key that knows the new order
words = 'hello world'
# Create to a List of the words and get the length as an Int.
# We don't actually need to cast it to a List in Python.
# Indexing Strings in Python works like a List.
@phalt
phalt / com.googlecode.iterm2.plist
Last active September 1, 2017 14:30
iterm2 config
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>AboutToPasteTabsWithCancel</key>
<true/>
<key>AboutToPasteTabsWithCancel_selection</key>
<integer>2</integer>
<key>AppleAntiAliasingThreshold</key>
<integer>1</integer>
@phalt
phalt / .bash_profile
Created September 4, 2017 15:52
bash_profile
# Virtualenv wrapper stuff
export WORKON_HOME=~/Envs
VIRTUALENVWRAPPER_PYTHON=/usr/local/bin/python3
source /usr/local/bin/virtualenvwrapper.sh
# Make sure virtualenv is active before using pip
export PIP_REQUIRE_VIRTUALENV=true
# Various git shorthands
alias gs="git status"
@phalt
phalt / abstract.py
Created September 7, 2017 09:00
Abstract Base models
from django.db import models
class DateTimeModel(models.Model):
class Meta:
abstract = True
date_created = models.DateTimeField(auto_now_add=True)
date_updated = models.DateTimeField(auto_now=True)
@phalt
phalt / ordered_set.py
Created December 7, 2017 13:55
Python 3.6 ordered set using a Dict
'''
In python 3.6 dictionaries are ordered:
"The order-preserving aspect of this new implementation
is considered an implementation detail and should
not be relied upon."
But let's face it, we're going to use it and it is
going to become a consistent feature.