instruction
stringlengths
71
95.1k
I have a parent object (a display window) and it has a few child objects (buttons and controls on the window). I would like one child object to hide itself when another is clicked. Currently, I have my parent object bind to a custom event expected to be fired from the child object. Then, the parent object passes the co...
I have been doing server-side development for a couple of years, but I am just now getting into doing some client-side programming. As a JavaScript exercise, I created a dead-simple jQuery image slider plugin, but I don't know if I did it the "right" way. Specifically, I was wondering what improvements ought to be made...
I've implemented the following two versions of the classic "Max Sub-Array" problem in Clojure, using the Kadane algorithm. First with loop / recur (defn max-sub-array [A] (loop [x (first A) a (rest A) max-ending-here 0 max-so-far 0] (if (seq a) (recur (first a) (rest a) (max x, (+...
I'm new to Java and have been reading Java for Dummies and other ones as well. I've started building this program like a week ago. I'm sure it's very messy. Just seeing if someone can clean it up and show easier ways of doing things. I have like 4 classes, but I'll just post the main class and a subclass for now. Here...
I'm trying to write a matlab function that creates random, smooth trajectories in a square of finite side length. Here is my current attempt at such a procedure: function [] = drawroutes( SideLength, v, t) %DRAWROUTES Summary of this function goes here % Detailed explanation goes here %Some parameters intended to h...
I implemented a queue capable of operating both in the FIFO mode and in the priority mode: when the priority mode is enabled, the elements are taken in order of decreasing priority; when the priority mode in disabled, the elements are taken in order of their arrival. In order to manage the priority, I thought of using ...
I have been developing a capitalizer in Python. This is actually a script that an end user will type at their terminal/command prompt. I have made this script to: Taking the first argument as a file name and process it. Don't process words that have 3 or less alphabet. Here's some code: #!/usr/bin/env python #-*- cod...
The subject is this small project - PHP/MySQL Database wrapper The three main goals of this projects are: Easy way to map database columns to object properties Simple solution to insert or update data Query builder class which generate sql query (something like ActiveRecord in CodeIgniter) Some examples: class User e...
I have written Validation and Form classes in PHP. Validation class allow you to define the rules of each field and a error message. Form class allow you to get a error message and also allow you to get a value of POST via $_SESSION. I stored in $_SESSION because if validation did not pass it will need to redirect ...
I have a catalogue of activities that are marked based on the age group that they are relevant to. There are 14 checkboxes for checking what grades. K, 1 - 12, and Adult. I have a switch statement to change the K and Adult to a numeric representation. The following PHP code grabs the grades checked and displays them in...
I want to build a set of builders for generating test data. On one side I want my builders API to be natural to use for my teammates. On the other side I'm great fun of creating DSLs, because it eliminates writing the same boilerplate code and let you read the code as English sentences. However, I found those require...
My Haskell set/map/list folds often become terse and difficult to read. I'm looking for tips on how to make my functional code easier to follow. I'm working around a bug/feature in a plotting library. I have a map from tags to lists of (time,count) which I plot as a stacked graph: import Data.Time (UTCTime)...
the following is my code for the Java class connection to mysql server, i need to see if there is any suggestion to make it better. this class not making the connection, it just control transactions, selecting, updating & deleting. package database; import java.sql.*; import java.util.*; import core.*; public class C...
My goal was to create class, that can run external method in non blocking manner. Second requirement was to be able to abort method run if it is needed (i.e. running user script). I decided to do that with Thread instead of Task, because only Thread can be truly aborted. Because Thread have big creation overhead, it is...
In the book Real World Haskell, the author writes in the first line of every file that uses, for example the following: file: ch05/PrettyJSON. The chapter slash and the name of a module. I wanted to create a script which reads the first line and copies the files to the appropriate directory. In the above example we sho...
I wanted something more flexible than System.Collections.ObjectModel.ReadOnlyCollection. The goal was: consuming classes should only see what I want to show them, not whole underlying collection. For example: I have an array of 10 elements. If I want to show consumer only first 5 elements, I don't want to create new Li...
I'm trying to write a function that finds the largest two numbers from a list of positive integers in Clojure. I've toyed around with Scheme in the past, but I'm very new to Clojure. This is what I came up with: ; Accumulator function for reduce later (defn top-two [acc x] (let [big1 (first acc) big2 (second acc)] ...
I have 2 input fields to input the duration of a CD song. The first input is for minutes and the second is for seconds When submitting the form, I must insert in the db the duration either in seconds (minutes + seconds) or NULL. Here's my validation formula: $warning = array(); function val_duration($min, $sec, $requi...
I have a problem from UVA online judge here. I have read it tons of times, and as they said, I have to get the answer really fast. I have used a binary search and std::sort, but I am still having a time error. I don't know any faster way of searching on an array other than binary search. Any feedback please? #include...
So I'm writing a program to format names to title case and display them in alphabetic order. Any advice please? And how can i add more methods? public static void main (String [] args) { //local variables string name1; string name2; myLib = new Library(); /******************** Start main...
There can be a business or security requirement that certain fields on a model should never be exposed in an API. One approach to this is to tell the developers not to ever put the field in the API output, but I prefer to protect them at the model level because that's where the requirement actually is. The goal of this...
Sometimes I need toString() to be quite verbose, normally I don't. It can't be nicely solved by using other methods as toString() is what gets shown in debugger (and also in the logs unless I call some method explicitly). As nobody should ever rely on its behavior, I wonder if the following is acceptable public static ...
The requirement is to be able to cache method invocations made on a boundary layer (Services layer). I'm using Unity to inject the concrete implementation of the Service layer classes. The intercepting CacheCallHandler caches all the responses across this layer. The twist is that this is a multi-threaded environment w...
I started learning java a few days ago. I prefer C++ but since I'll need java this college semester I decided to learn a few things to ease myself in. Anyway in C++ I always used a foolproof input method for taking user input of primitive numeric types. I picked that method up from here. So I decided to somewhat transf...
Ok so this works as is, and is not actually slow at all (from what I can see) - However I don't like the taste of nested while loops and was wondering if anyone could give some insight on a different approach? Or how to improve mine to take away the while() { while() {}} Here it is: /* takes a string and a maxWidth an...
I'm interested in discussing string literals in Objective-C and would like to know 1. if there's a preferred paradigm / style and 2. what (if any) the performance implications might be. There are parts of the Cocoa / CocoaTouch frameworks that use strings as identifiers. Some examples in Cocoa / CocoaTouch... -[NSNotif...
I am wondering if the self invoking function as displayed below, mainly the part of using the same function twice ('foo')('bar'), would ever be seen as a good practice? And more important, is there a good reason to use this? Personally in this particular example I would rather go for multiple attributes and loop those....
I have an object, WorkflowGridBuilder, which is responsible for building a jqGrid object and decorating it appropriately based on the type of grid being built. Here is my builder: var WorkflowGridBuilder; $(WorkflowGridBuilder = function () { 'use strict'; function buildGrid(data) { var grid = $('#' +...
I need to generate a Ruby hash that looks like this: { "children" => [ { "children" => [ { "children" => [ { "children" => [] } ]} ]} ]} ... for an arbitrary level of nesting. So far the best I've come up with is: def nested_hash(levels) return {} if levels < 1 root = { 'children' => [] } chil...
In getting accustomed to Clojure syntax, I wrote the following stutter function: (defn doublelist [coll] (flatten (map (fn [x] [x x]) coll))) (defn stutter [s] (clojure.string/join " " (doublelist (clojure.string/split s #" ")))) This duplicates every word in an input string: (stutter "how are you?") "how how...
I'm working alone on my code, trying to learn Ruby as I go. Class Robot is supposed to be instantiated with the position on a map, and whether it is facing toward a side of the map. It has a couple of moves: left or right, where the face of the robot changes direction, and a move action, one step forward. class Robot ...
could you please review the code for the implementation of the class (link: General review of Robot class) require_relative 'robot' class Game def initialize # initialize values @commands = %w{PLACE MOVE LEFT RIGHT REPORT} @facings = %w{NORTH SOUTH EAST WEST} @pos_X, @pos_Y = nil, nil @facing, @r...
I wrote the following code for a Dynamic Programming problem but the online judge gives me a 'Time Limit Exceeded' error. How can I optimize this code to make it more efficient, especially the part of initializing the DP array to 0.0 (I am using memset() right now)? Problem: There are N values in an array. Two player...
I was trying to figure out how to make a breakable foreach macro for STL containers and I came up with this method that uses templates to recognize the container type automatically. Are there any performance / code-wise improvements you can think of? // polymorphic break-able foreach test that works with nested calls o...
How can I simplify this jQuery code? I feel like I should be able to do this with one click function. jQuery $('.btn').eq(0).click(function () { $('.carousel').css({ 'left': '0%' }); }); $('.btn').eq(1).click(function () { $('.carousel').css({ 'left': '-100%' }); }); $('.btn').eq(2).click(function () { $('.carousel').c...
I have two lists with ca. 4000 elements where each each element have two columns. These are being fed into a function. Besides the function they are being fed into, is it possible to speed it up somehow? At this rate, it will take ca. 6-7 days to complete. results=rep(0, length(as.numeric(unlist(coors)))) for(i in name...
I want to implement numbering scheme like Microsoft Word uses for numbering. first one gets = A,next is B, next is C, .... then AA, then AB,....and so on. as shown below A B C . . AA AB AC . . AAA AAB .... '=>' here means converted to. some examples: 1 => A 26 => Z 27 => AA 52 => AZ 53 => B...
I quite like this extra credit assignment I did for Zed Shaw's Learn Python The Hard Way. Its a neat little text adventure game that uses stats. I would like to eventually expand this, but let me know how the code looks so far! # Legend Of Doobieus import random from sys import exit #rolls 3d6 def roll_3d6(): ...
I have the following Ruby code in an RSpec file: describe "order" do before do LIST_LENGTH ||= 10 @skills = FactoryGirl.create_list(:skill, LIST_LENGTH) @developer = FactoryGirl.create(:user) @requests = FactoryGirl.create_list(:request, LIST_LENGTH) LIST_LENGTH.times { |i| @requests...
This method receives an array of data and does some stuff in a database. I need to get some reviews on it if possible. public function doSomeStuff($arr = array()) { $id = $arr['Employee']['id']; $name = $arr['Employee']['name']; $status = $arr['Employee']['status'] == 'Disabled' ? 0 : 1; $user_id = $ar...
Below is my implementation of a stack in C. Is it correct? And/or is there anything that I should fix to make it better in any way? stack.h #ifndef STACK_H #define STACK_H #define EMPTY_STACK -1 typedef struct stack { char ch; struct stack* prev; } Stack; extern Stack* init_stack(void); extern char pop(Stack*); e...
I have this code that basically reads the DOM and sends the values to the server. I am looking for any possible flaws that I may have in this JavaScript code and any advice to make it better and bug-free! $(document).ready(function () { $('.editButton').click(function () { var postData = {}; var cDa...
I'm a bit novice/moderate at JS. To my surprise I managed to put this together and it does work for what I intended. The objective is to convert an object into a format that is more conducive to being used with a treegrid. I'm using the underscore library to grab object keys at various points. I just wanted to know if...
I wrote a wrapper library for a REST API in Perl using the Moose library. I would like to gather some feedback on it (mainly on the OOP part since I am new to moose), before pushing it out. Base class: has 'debug' => (is => 'rw', isa => 'Bool', default => 0); has 'api_key' => (is => 'ro', isa => 'Str', re...
I'm creating some age-verification functionality for an iOS app. The user is presented with a UIDatePicker object, and the latest selectable date should be today minus 18 years. How vulnerable to inaccuracy is my code? How could it be leaner? -(void)validateAge { NSDateComponents *today = [[NSCalendar currentCalen...
I know about the "little bobby tables" scenario and was just wondering if this code is vulnerable to such SQL injections. I am fairly new to PHP and am curious about this. My code for a login script: <?php # session session_start(); # get the variables from login.php $userid = $_POST["userid"]; $pword = $_PO...
My app saves data to a file - I obviously don't want the app to write to the file from multiple locations on disk. What I want is a generic "utility" class that will know how to run a piece of code (let's call it SingletonTask) with the following rules: Only one SingletonTask will run at any given moment in the system...
I have got such 2d jagged array (row is 1st dimension, column is 2nd dimension, bottom to up, left to right) 0 0 b b b c 0 0 h g g c 0 0 h a a c 0 0 f f d d 0 0 i j e e 0 0 i j 0 0 I would like to get a 2d jagged array summarize the positions of consecutive e...
I posted this an answer this to a question about drawing a random line from a file too large to put into memory. I hacked the below code together. In essence, this is what Reservoir Sampling does, in pseudo-code: Scan over the 'tape' Put the first 'n' samples in a reservoir(of size n) // samples are lines of a ...
If you notice, there are variables of street_address, route, intersection re-used in the entire code base. They are actually from Google Maps geocoder address components. How can I refactor this one so that I don't have to declare them one by one? Note that in the geocoder address components, those 3 mentioned above ar...
I was just trying to make an alternate Ajax watermark from "insert date" (first mode) to "mm/dd/yyyy" (second mode). After some trial and error, I successfully implemented a solution using JavaScript. How can I improve this script functionality? JavaScript: var original = "insert date"; var alternate = "mmddyyyy"; var ...
I am calculating discounts based on a quantity after 6. Is there a cleaner way to do this: $leg_directory_discount = array( 6 => .50, 7 => .50, 8 => .50, 9 => .50, 10 => .50, 11 => 1, 12 => 1, 13 => 1, 14 => 1, 15 => 1, 16 => 1, 17 => 1, 1...
The Problem I have a cursor that I am trying to replace (perhaps unnecessarily) in an attempt to clean up a stored procedure. Essentially what it is doing is counting each note for each member in a temp table and then assigning each of those notes a sequential value into the field NOTE_COUNTER (int) of the temp table. ...
I need to calculate checksum using 16-bit ones' complement addition: while(byte>0) //len = Total num of bytes { Word = ((Buf[i]<<8) + Buf[i+1]) + Checksum; //get two bytes at a time and add previous calculated checsum value Checksum = Word & 0x0FFFF; //Discard the carry if any Word = (Word>>16); //K...
/* Infinite Scroll Pagination with a Wookmark layout * * Requires: jQuery, Wookmark */ var myApp = myApp || {}; ;(function(myApp,$){ var WookmarkPagination = function(elem, options){ this.elem = elem; this.$elem = $(elem); this.options = options; }; WookmarkPagination.prototype = { defaults:...
First off I would like to state that this is a homework assignment. However, I am not looking for you to complete anything for me. I code I am posting is the completed homework assignment. However, since this is my first time using C++ I was curious if there might have been a better method to accomplish the same task. ...
I wrote a C# tool that make a recursive search. I need the file size and the size on disc. I am using a function that give me the size on disc but it is very slow. Is there any other way to do it except the following code? public void RecursiveSearch(string path) { try { foreach (string dir in Directory...
How to write following if condition clean/fast/readable. Any one of the fields 'address', 'city', 'district', 'province' can be null. I want to make full address by concat all these fields. Like address = "Street # 32" city = "My City" District = "New York" Province = "NY" fullAddress = "Stree #32, My City, New York,...
The bellow functions are used to generate a string with random characters, and they have a parameter to specify the string length. The string can be composed of letters, numbers or a conjunction of both. I've been using this for a very long time now, and currently, I look at it and it seems to damn extensive for the en...
I have three input boxes that are all linked to each other by some pretty basic rules: Editing the page title will copy the contents to menu title Unless menu title has been manually edited clearing menu title sets it back to automatic Editing the menu title will copy the contents as a url slug to slug Unless the ...
I have a php authentication script and everything works fine, but I'm very unsure about the way I programmed it (I hardcoded some things). I was hoping stack could look through this and point out any potential problems. Here's the script: <?php require_once 'Bcrypt.php'; class Mysql { private $conn; function _...
I'm a complete PHP beginner and would like some feedback on this registration page I've created. Now, the one thing I know right off that bat that's wrong with it is that there's WAY too much commenting. This was for my benefit to help teach myself as I went along and help avoid confusion as I read back through my cod...
I made a simple library to help me doing A/B tests in a web app. The idea is simple: I have two or more page options (URL) for a given page and every call to the library method should give me a URL so at the end all options were given the same traffic. My questions are: Is this 100% thread safe? Is this performatic ...
This is an ordinary data processing task: read a list of dates and amounts (for example, deposits and withdrawals from a bank account) and report the date on which the lowest balance was recorded and what that balance was. While I do get the correct answer--always a virtue--with the code below, I can't help thinking th...
Is there any problem in checking PHP PDO connection this manner? Is this way reliable? function pdo_mysql() { $mysql_string = "xxxxxxxxxxx"; $mysql_user = "xxxxxxxxxxx"; $mysql_pass = "xxxxxxxxxxx"; try { $pdo_mysql = new PDO( $mysql_string, $mysql_user, $mysql_pass ); $pdo_mysql->setAttribute( PDO::ATTR_ERRM...
var EVENT_TYPE = "touchstart" // Global Event Type var H = 360, S = 1.0, V = 1.0 var randomColorsList = [], staticColorsList = [ [r = 255, g = 56, b = 30], [r = 22, g = 20, b = 32], [r...
I'm working on a project in which the previous programmer seems to have loved using the AS keyword in the SELECT part of queries. I really don't like how it's written but if there is no performance difference I won't change existing code. My tests did give a slight advantage to not using the AS keyword but I'm clueless...
I'm working now on project, which is need some read more functionality and I tried to write this jquery plugin and share it in my github account. Here is the full listing of code: ;(function ( $, window, document, undefined ) { function get_link(readmore_wrap_class, readmore_class, readmore_text ) { return $('<a/>...
Following is a chunk of code from my class which generates PDF documents. I am refactoring my code and in the process I have created short methods. But I have to pass 'table i.e PdfPTable' to my methods again and again. How can I avoid this? PdfPTable orgTable = new PdfPTable(2); PdfPCell cell = null; string orgName = ...
I need to check the end of a URL for the possible existence of /news_archive or /news_archive/5 in PHP. The below snippet does exactly what I want, but I know that I could achieve this with one preg_match rather than two. How can I improve this code to treat the /5 as an optional segment and capture it if it exists? if...
This is my first jQuery plugin. It is a simple slider that requires very little mark up in html. It works for my purposes but I am not a jQuery expert and I am wondering if there are mistakes or shortcuts that I took in its creation. Thank you for taking a look at the plugin! The HTML <script type="text/javascript"> ...
I'm starting to learn how to meld the worlds of C and Haskell. Looking for any feedback on this first function. The function takes in a pointer to an array of unsigned chars and returns a pointer to 32 unsigned shorts. Or at least I would like it too :). I am unsure about when the memory used to return the result is cl...
So, I needed to make me a register script for my website so pepole can register, and just wanted to know if It's okey. So, is there any vulns in this script i made?It works perfectly, just that i wanted to have someone to look over it here. Or if there could be some inprovments that could make it better. <?php ...
The following is my wordsearch solving algorithm. I'd greatly appreciate tips on how to improve it (e.g. improve efficiency, better approach, etc.): public boolean traverse(Grid grid) { for (int r = 0; r < grid.getRows(); r++) { for (int c = 0; c < grid.getCols(); c++) { for (Direction direction...
I have the below function, it is designed so I can call: $object->temp('one', 1); //add the key `one` to the temp array with value 1 $object->temp('two', 2); //add the key `two` to the temp array with value 2 $object->temp('three', 3); //add the key `three` to the temp array with value 3 $object->temp('three');...
I sat down to write a demo HTML5-ish page that lets a user to perform following operations on a canvas - draw lines, draw a filled rectangle, and reset the canvas. Each operation is represented by a button, clicking on which the operation is carried out. My initial attempt ended up as a mingled HTML and JavaScript code...
I have this function in my application that I need to simplify in order to improve the code quality: void FilterValues() { List<SecondaryStockRoomDefenition> GridViewItems = new List<SecondaryStockRoomDefenition>(); GridViewItems = StockRooms.ToList(); if (cboPrimaryStockRoom.SelectedValue....
I have a N*N upper triangular matrix with property such that, all its diagonal elements are a1,a2,a3,...,aN. I want that a[i][j] (for all j>i) should be (a[i][j-1] + a[i+1][j]) / 2. I have many test cases, and I have to apply this property every time to calculate the answer. What is the most optimal way to do this, so...
I am learning Java Collections Framework. Can someone look at this code for generating all subsets of a given set and tell me any issues with it. import java.util.*; public class AllSubsets { public static void main(String[] args) { Set<Integer> original = new HashSet<Integer>(); for (int i = Intege...
I defined the class Rectangle: class Rectangle attr_reader :b, :h def initialize(b, h) @b = b @h = h end def area @b*@h end def to_s "Rectangle #{@b}x{@h}" end end and its subclass Square: class Square < Rectangle attr_reader :s def initialize(s) @s = s super(@s, @s) end ...
I think this code to parse a contrived message protocol with first byte data length followed by data is a little ugly. Has anyone got any suggestions on how to make it more elegant and more robust? #include <stdio.h> #include <stdlib.h> #include <string.h> #define LENGTHBYTES 1 void splitmessages(unsigned char* bstr...
I have two different set of checkboxes. With the coffescript code below I set the maximum amount of checkable items at 3. I would like to refactor this code, to be cleaner and compact, but I can't get it. $("div.feature_list :checkbox").click -> if $("div.feature_list :checked").length >= 3 $("div.feature_list :c...
This code works fine, but I just don't like all the if else. If I keep adding field to filter, it's going to get messy. I am not using EF and cannot on this. Controller code: var books = bookRepository.GetDogs(); if (!String.IsNullOrEmpty(searchString)) { if (!String.IsNullOrWhiteSpace(searchString) && search...
I have the following which searches my graph to see if a vertex is reachable from the first vertex, which everything should be connected to. I do this to ensure there are no disconnected parts. Unfortunately it is very slow. Is there something I could do or store to optimize this? I want to learn about graphs and gener...
I started porting an API wrapper from Java to Python for practice. I am looking for ways to improve the readability/maintainability this code. I have done some reading about "pythonic" style and I am hoping someone could provide some feedback as to how one goes about making their code more pythonic. All source can be f...
What does this script tell you about how I need to improve as a programmer? I'm somewhat new to both Python and programming, so feel free to minimize your assumptions about my knowledge. The purpose of this script is to read a .csv of names and emails addresses that are improperly organized -- sometimes there is only...
This is the way I handle an Ajax response. I am sure it can be improved. success: function (json) { $.each(json, function(index,item){ if (item.field == "article_id") { $("#article_id").val(item.value); } els...
I am currently reading The C Programming Language by Dennis Richie and Brian Kernighan, and I came to implement the function squeeze (s1, s2) as an exercise. squeeze() deletes each character in s1 that matches any character in the string s2. While coding squeeze(), I thought that I can extend its capability to act like...
It's my first window program. It simply searches for a specified file in the whole computer. File Search.h (header file that contains the prototypes of fileSearcher class methods.) #ifndef UNICODE #define UNICODE #endif #include <Windows.h> #include <queue> namespace fileSearch { class fileSearcher { public: fi...
I'm teaching myself Python via Zed Shaw's LPTHW and he suggested to me that I try to condense my code so I can call up bits of it within a function. Right now this is boggling my mind and I can't figure out a way to condense it that doesn't result in an error regarding global and local variables in reference to weapons...
I need to merge two objects in a code path that is going to be heavily used. The code works, but I am concerned it is not optimized enough for speed and I am looking for any suggestions to improve/replace what I have come up with. I originally started working off an example at the end of this issue: https://stackover...
I've been learning about Monte Carlo simulations on MIT's intro to programming class, and I'm trying to implement one that calculates the probability of flipping a coin heads side up 4 times in a row out of ten flips. Basically, I calculate if the current flip in a 10 flip session is equal to the prior flip, and if it ...
I am trying to append data to a table based on the ajax returned data. My codes work but it seems ugly. I was wondering if anyone here can help me to simplfy it. Thanks a lot! ajax.callback=function(data){ for (var i=0; i<dataObj[0].data.length; i++){ var td=document.createElement('td'); ...
Can't seem to find one, so trying to build a very simple but fast implementation. Thought I would post on SO for review/feedback, and so that others can just copy/paste for their own use. I'm using a Dictionary and LinkedList, with a non-granular lock. Basic benchmark included below: public class LRUDictionary<TKey,TV...
Problem: Given a set of n distinct numbers, find the length of the longest monotone increasing subsequence. For example, let's take this array [1,2,9,4,7,3,11,8,14,6] The longest monotone increasing subsequence of this array is [1,2,4,7,11,14]. So the desired result is, the length of the array which is 6. Algorithm (ta...
Current best practice for using a lock_guard looks like this: // introduce scope to take the lock { lock_guard lock(sync); // sync is an accessible mutex object do_protected_stuff(); // may throw, but the mutex is released regardless } // no exception, mutex is released in normal flow I don't like the s...
I have the following class which is a tool for retrieving MD5 hashes of files that are input into it. They can potentially be very large files and I require cancellation and progress report, hence why i rolled my own solution rather than just passing in a filestream to HashAlgorithm. I have a producer - consumer set up...
This is my first time working with classes and it's still unclear to me. I was wondering if someone can tell me if I did this right. Define a new class, Track, that has an artist (a string), a title (also a string), and an album (see below). Has a method __init__(self, artist, title, album=None). The arguments arti...
I'm new to Python and would like some advice or guidance moving forward. I'm trying to parse Wikipedia data into something uniform that I can put into a database. I've looked at wiki parsers but from what I can see they are large and complex and don't get me much as I don't need 99% of their functionality (I'm not edit...
Very simple I want to edit a virtual host files and replace the tags I made with some actual data: import os, re with open('virt_host', 'r+') as virtual file = virtual.read() file = re.sub('{{dir}}', '/home/richard', file) file = re.sub('{{user}}', 'richard', file) file = re.sub('{{domain_name}}', 'rich...