Skip to content

Instantly share code, notes, and snippets.

View arto-heino's full-sized avatar

Arto Heino arto-heino

View GitHub Profile
list = os.listdir(path)
# Files are now named ssn_filename_uniqueid.filetype
# Set files to list ['filename','unique_id','file_type']
def renameFiles(list):
name = []
for filename in list:
name.append(re.split("(_\d*_\d*_\d*)", filename))
return name
def getFiles(list):
#!/usr/bin/env python
import os
# First get the folder name (SSN) and save it
folderlist = [name for name in os.listdir(".") if os.path.isdir(name)]
# Second get filelist on folder
def new_list(x):
for ssn in x:
for filename in os.listdir(ssn):
new_name = str(ssn) + '_' + str(filename)
#!/usr/bin/env python
import os
# First get the folder name (SSN) and save it
folderlist = [name for name in os.listdir(".") if os.path.isdir(name)]
# Second get filelist on folder
def new_list(x):
a = {}
for i in x:
a[i] = {'old_name' : os.listdir(i)}, {'new_name' : os.listdir(i)}
public function composeData($file){
$f = fopen($file, 'r');
while(!feof($f))
{
$line = fgets($f);
if(empty($line))
return;
$lineData = explode('|', $line);
@arto-heino
arto-heino / merge_questions.php
Created June 14, 2017 08:16
Problem with array mergin.
$questions = array('TherapygroupQuestions' =>
array('id' => 1,'question' => "How much this hurt?"),
array('id' => 2, 'question' => "How much your feet hurt?"),
array('id' => 3, 'question' => "How much your hand hurt?")
);
$answers = array('TherapygroupAnswers' =>
array('id' => 3, 'question_id' => 1, 'answer' => 1),
array('id' => 5, 'question_id' => 3, 'answer' => 5)
);
@arto-heino
arto-heino / kysymykset.php
Created June 7, 2017 14:45
kysymykset_vasgtaukset
for($i=0;$i<count($kysymykset);$i++){
if(count($vastaukset) > 0){
foreach($vastaukset as $key){
if ($kysymykset[$i]['TherapygroupQuestions']['id'] == $key['TherapygroupAnswers']['question_id']) {
$kysymykset_vastaukset[$i] = array_merge($kysymykset[$i]['TherapygroupQuestions'], array('vastaus' => $key['TherapygroupAnswers']['vastaus'], 'vastaus_id' => $key['TherapygroupAnswers']['id']));
}
}
}else{
$kysymykset_vastaukset[$i] = array_merge($kysymykset[$i]['TherapygroupQuestions']);
}
I have two arrays, questions and answers. I need to merge them together so in question there are its answer if it have answer.
This is how it should look like:
array(‘questions’ =>
array(‘id’=> 1,
’question’ => ‘How sick you are’,
‘answer’ => 3))
And if there are no answer it should only show the question.
PodcastTableViewController.swift
class PodcastTableViewController: UITableViewController, DataParserObserver {
var podcasts = [Podcast]()
override func viewDidLoad() {
super.viewDidLoad()
self.podcasts = [Podcast]()
class PodcastTableViewController: UITableViewController, DataParserObserver {
var podcasts = [Podcast]()
override func viewDidLoad() {
super.viewDidLoad()
self.podcasts = [Podcast]()
let dataParser = HttpRequesting()
dataParser.httpGetPodCasts(parserObserver: self)
func httpGetApi () {
let parameters: Parameters = ["username": "username", "password": "password"]
Alamofire.request("addr", method: .post, parameters:parameters, encoding: JSONEncoding.default)
.responseJSON{response in
if let json = response.result.value as? [String: String] {
self.setApiKey(apiKey: json["api_key"]!)
}else{
self.setMessage(statusMessage: "Ei toimi")