Skip to content

Instantly share code, notes, and snippets.

View f-ewald's full-sized avatar

Freddy f-ewald

View GitHub Profile
@f-ewald
f-ewald / sample.py
Created July 7, 2018 21:07
Calculate mean value per row of sparse matrix
import numpy
from scipy.sparse import csr_matrix
A = numpy.array([[0, 0, 1],[0,2,4]])
# array([[0, 0, 1],
# [0, 2, 4]])
B = csr_matrix(A)
d = B.getnnz(axis=1) # Get number of non zero entries
print(d)
# array([1, 2], dtype=int32)
print(B.sum(axis=1).A.reshape(-1)/d)
class OptimizationJob(models.Model):
def generate_primary_key():
no = randint(13537086546263552, 839299365868340223)
str_no = Base62.encode(no)
result_count = OptimizationJob.objects.filter(job_id=str_no).count()
while result_count > 0:
no = randint(13537086546263552, 839299365868340223)
str_no = Base62.encode(no)
result_count = OptimizationJob.objects.filter(job_id=str_no).count()
return str_no
@f-ewald
f-ewald / docker_cleanup.sh
Created February 13, 2017 20:02
Docker Cleanup
# stop all containers
docker-compose stop
# Remove all containers
docker rm -v $(docker ps -a -q)
# Remove all images
docker rmi $(docker images -q)
# Remove all volumes
@f-ewald
f-ewald / example.py
Created December 9, 2016 02:41
Basic scipy example
from scipy import optimize
def objective_function(x):
return x[0] + x[1]
def constraint1(x):
# x + y == 12
return x[0] + x[1] - 12
@f-ewald
f-ewald / column_converter.py
Last active September 14, 2016 01:56
Format column number Excel like to a cell letter
def get_column_letter(column_no):
"""
A = 0
Z = 25
AA = 26
AB = 27
BA = 52
:param column_no: The 0-based column index.
:return: The column as a combination of letters.
"""
@f-ewald
f-ewald / program.cs
Last active July 27, 2016 23:36
async/await c#
using System;
using System.ComponentModel;
using System.Text;
using System.Threading.Tasks;
namespace MultiThreadTest
{
class Program
{
static void Main(string[] args)
@f-ewald
f-ewald / BeaconDetector.h
Created February 19, 2016 18:03
Beacon Detector
//
// BeaconDetector.h
// WMWallet
//
// Created by Friedrich Ewald on 18.02.16.
// Copyright © 2016 fewald. All rights reserved.
//
#import <Foundation/Foundation.h>
@import CoreLocation;
@f-ewald
f-ewald / file_combiner.py
Created October 22, 2015 16:55
Combines files by filename into one
# file combiner
# combines csv files into one
import os
for f in os.listdir('export'):
print 'Processing file %s' % f
with open('export/' + f, 'r') as h:
filename = str()
if f.endswith('electricityrates.csv'):
@f-ewald
f-ewald / file_formatter.py
Created October 22, 2015 16:12
File formatter to add identifiers to lines in csv files
# file formatter for csv files
import os
ctr = 6
cctr = 0
for f in os.listdir('to import'):
print 'Processing file %s' % f
with open('to import/' + f, 'r') as h:
@f-ewald
f-ewald / 6_1.hive
Last active September 12, 2017 09:45
Ex06
INSERT OVERWRITE LOCAL DIRECTORY '${hiveconf:output_file}'
ROW FORMAT DELIMITED
FIELDS TERMINATED BY ','
SELECT hashtag.object, COUNT(*) as amount
FROM
${hiveconf:table} t1
JOIN
${hiveconf:table} t2
ON