Skip to content

Instantly share code, notes, and snippets.

# Java Maven CircleCI 2.0 configuration file
#
# Check https://circleci.com/docs/2.0/language-java/ for more details
#
version: 2
jobs:
build:
docker:
# specify the version you desire here
- image: circleci/openjdk:8-jdk
@smaspe
smaspe / heapsort.py
Created July 11, 2017 02:29
A quick implementation of heapsort
parent_index = lambda x: (x - 1) / 2
left_child_index = lambda x: 2 * x + 1
def heapsort(arr):
"""
sorts the given list using heapsort
"""
heapify(arr)
print_heap(arr)
sort_heap(arr)
@smaspe
smaspe / codeeval_asciidescription.py
Last active January 12, 2016 22:03
A code eval challenge solved some other way
# A side-step solution because I was too lazy to find the repeated word...
# It find the most common letter, but exclude ' ', which is the lowest value and is often more common than 'e'
import sys
from collections import Counter
with open(sys.argv[1], 'r') as test_cases:
for test in test_cases:
vals = map(int, test.split('|')[2].strip().split(' '))
m = min(vals)
e = Counter(v for v in vals if v != m).most_common(1)[0][0]
from collections import Counter
size = 11
tab = [None] * size*size
def split(t):
return [t[size*i:size*i+size] for i in range(size)]
def splitV(t):
@smaspe
smaspe / UriTest.java
Created October 22, 2015 18:16
Tests on Uri query parameters
import android.net.Uri;
import android.test.InstrumentationTestCase;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
public class UriTest extends InstrumentationTestCase {
public void testQueryParameters() throws UnsupportedEncodingException {
Uri uri = Uri.parse("http://domain.com/test?single_value=1");
import itertools
letters = "acdegilmnoprstuw"
value = 25180466553932
def hsh(s):
return reduce(lambda h, char: h * 37 + letters.index(char), s, 7)
def unhash(val):
return unhash(val / 37) + letters[val % 37] if val > 7 else ''
@smaspe
smaspe / .profile
Created October 28, 2013 18:48 — forked from anonymous/.profile
source ~/git-completion.bash
source ~/git-prompt.sh
export RES='$(if [[ $? = 0 ]]; then echo -e "\e[0;32m\xe2\x9c\x94\e[m"; else echo -e "\e[0;31m\xe2\x9c\x98\e[m"; fi;)'
export PS1="$RES \e[1;36m\t\e[m\e[0;33m(\u)\e[m\e[40m\e[37m\w\e[m\e[1;35m\$(__git_ps1)\e[m\n\$ "
alias l='ls'
alias ll='ls -l'
alias less='less -N'
private static final String SNAPR_URL = "http://sna.pr/api/search/";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1);
setListAdapter(adapter);
new Downloader(adapter).execute(SNAPR_URL);
}
for (int i = 0; i < images.length(); i++) {
JSONObject object = images.optJSONObject(i);
if (object != null) {
mAdapter.add(object.optString("description"));
}
}
JSONObject response = new JSONObject(EntityUtils.toString(
new DefaultHttpClient().execute(
new HttpGet(params[0])).getEntity(), "UTF-8"));
if (response.optBoolean("success", false)) {
return response.getJSONObject("response").getJSONArray("photos");
} else {
Log.w(TAG, "Request failed. Details: " + response.toString(2));
}