Skip to content

Instantly share code, notes, and snippets.

@odedlaz
odedlaz / ToDecimal.java
Created November 7, 2015 16:50
ToDecimal exercise
public class ToDecimal {
public static void main(String[] args) {
if (args.length == 0) {
System.out.println("illegal input");
return;
}
String decimalInBinary = args[0];
if (!decimalInBinary.matches("^(0|1)+$")) {
@odedlaz
odedlaz / Functions.java
Last active November 27, 2015 19:04
Explanation how functions work
import java.util.Arrays;
public class Functions {
public static int powerOfTwo(int x) {
int num = x*x;
System.out.printf("%d^2: %d\n", x, num);
return x*x;
}
@odedlaz
odedlaz / mathmatician.py
Last active December 1, 2015 18:03
download all mathmaticians from enealogy.math.ndsu.nodak.edu to a csv file
from collections import defaultdict
from pyquery import PyQuery
import csv
# the format for the id
url_format = url_format = "http://genealogy.math.ndsu.nodak.edu/id.php?id=%d"
# the response message when there is no id
# I hope there are no spaces in between, that is:
# id 3 exists, id 4 doesn't but id 5 does exist.
@odedlaz
odedlaz / expand_Dockerfile
Created January 25, 2016 15:47
Dockerfile for playing with expansions
FROM ubuntu
ENTRYPOINT ["/root/expand.sh"]
ADD do.sh /root/expand.sh
RUN chmod u+x /root/expand.sh
CMD ["a b c d $variable"]
@odedlaz
odedlaz / expand.sh
Created January 25, 2016 15:48
variable expansion script
#!/bin/bash
echo "before expanstion: $@"
eval "echo after expansion: $@"
@odedlaz
odedlaz / mary_hw.py
Last active February 9, 2016 19:10
mary hw
########### hw 4 #############
print([num for num in xrange(1000) if sum(map(int, str(num))) == 10])
################ hw 5 ################
def occ(n, specific):
for num in xrange(n):
times = len([x for x in str(num) if str(specific) == x])
yield (num, times)
@odedlaz
odedlaz / pyPasswordChameleon.py
Last active November 17, 2016 08:10
python implementation of password chameleon generator
from __future__ import print_function
import re
import sys
import hashlib
from select import select
from getpass import getpass
from base64 import b64encode
from os.path import expanduser
b64c = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="
from __future__ import print_function
import gc
import sys
import time
class TimeIt(object):
def __init__(self, scope_name="", fd=sys.stdout):
self._start = None
self._fd = fd
from __future__ import print_function
import os
import sys
# look at timeit.py gist
# https://gist.github.com/odedlaz/7811f703cc30a9d266817eaa4014ba7a
from random import randint
from timeit import TimeIt
from six.moves import range, cStringIO
@odedlaz
odedlaz / PyBytes_Concat.c
Created December 1, 2016 10:22
PyBytes_Concat
void
PyBytes_Concat(PyObject **pv, PyObject *w)
{
assert(pv != NULL);
if (*pv == NULL)
return;
if (w == NULL) {
Py_CLEAR(*pv);
return;
}