instruction
stringlengths
71
71.9k
Scenario: I am using a helper class called 'OutputHelper' to add a new record to the table 'Output'. My 'Output' object contains the following: ShiftID Model WorksOrder LotNo Quantity ShiftHour I do not want a record to be added if a record already exists with the ShiftID and ShiftHour of the record that I am trying...
In researching the new .NET Async and Await keywords in .NET 4.5, I created a simple example showing how to update a progress bar and a label while an async function is running. I also included how to cancel the process while it is taking place. To use the code below, create a Windows form and include two buttons: But...
For example, with this differential equation, how can I do it in a pythonic way? dx/dt=f(x,t) I have a way to do it, but I think this is not the most pythonic way: import numpy as np dt=0.01 N_iter=10./dt def f(x,t): return x**2*t#insert your favorite function here x=np.zeros(N_iter) for i in range(N_iter-1): ...
I was using brute force to remove duplicate words since the lists were really small. But I want a solution that won't become too slow if the input grows. This function creates a binary tree and inserts all words appearing on the list, then collects the unique words without sorting. Duplicate words are handled during in...
For exercise, I wrote this code: def BigPrime(numP, plist = [], x = 1, counter =0): while len(plist) <= numP: if x == 1 or x == 2 or x == 5: plist.append(x) elif x % 2 is not 0 and int(str(x)[-1]) is not 5: for div in plist[1:]: if x % div == 0...
I have a Factory class for a queuing system I'm playing around with. Consuming classes only care that they get a particular interface (Job) as a result of calling the factory's load method. Some Jobs may require a database connection, so I want to inject a PDO instance. Others may require something else, and I don't w...
This is an implementation of Bloom filter with add and contain functionality. I'm looking for code review, best practices, optimizations etc. I'm also verifying complexity: \$O(1)\$ public class BloomFilter<E> { private final BitSet bitSet; private final int hashFunctionCount; private final MessageDigest ...
Rewrite the routines day_of_year and month_day with pointers instead of indexing. The exercise is quite simple, this is the solution: int day_of_year(unsigned int year, int month, int day) { int leap, i; leap = ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)); if((month >= 1 && month <= 12) && ...
The following code is helpful to anyone who uses websockets in general... and is probably good template for anyone getting started in this area. I'd like to flesh this out into something that is more general purpose, and reusable, since the assumptions and questions I have will apply to many different situations. Ass...
I am currently in a data-structures class. The professor will be providing a singly linked list. I wanted to make a doubly linked list to "learn" how to do it. I tested it and I think it works. After making it, I did compare it to other doubly linked lists but I still want to see if there is anything I am missing. Are...
I have been playing around with some improvements to some sort algorithms like Selection Sort and Merge Sort and I ended up needing some sort of measurement to check if my versions were any faster than the original algorithm form. I also had a need to implement some sort of time measurement before but never did it, so ...
Because I was spoiled with C# and the .NET framework, whenever I have to work with VB6 I feel like something's missing in the language. A little while ago I implemented a List<T> for VB6 (here), and before that I implemented String.Format() and a number of string-helper functions (here). Don't go looking for a StringFo...
Is this the correct way to implement a thread-safe concurrent FIFO queue in C++? It requires passing unsigned char* arrays of binary data. Thread Safe Concurrent Queue #include <queue> #include <pthread.h> class concurrent_queue { private: std::queue<unsigned char*> _queue_; pthread_mutex_t push_mutex; ...
I always add an exception handler when a new method is created, and I don't know if it is a good or bad practice. I thought it may be a bit of an annoyance when viewing the source code. Is it a good practice to put logging functions in the exception block? def insert_new_camera(self, camera, records, file_hdlr): t...
A user must query a large database for information repeatedly. This query may take up to ~7 seconds. This must be done asynchronously. Only one query will be running at a time. I did not create a new thread for each query as the code would be less clean, less maintable, etc. I did not use ThreadPool.QueueUserWorkItem ...
I need a little help in finding a better solution. In the screen shot below any change to the forecast line I need to find the value in column B. The screen shot is only a sample in my production sheet the row count is currently 4200. Column A Col B Col C Col D Col E Row 5 January Row 6 ...
This code lists the permutations of the string, and eliminates duplicates if any. I'm looking for code review, best practices, optimizations etc. I'm also verifying complexity: \$O(n! * n)\$ as time complexity and \$O(n * n)\$ as space complexity, where \$n\$ is length of the input string. public final class Permutatio...
I've written an Erlang implementation of the genetic algorithm for a "Hello World" program as described here. This is my first time writing any code in Erlang and also my first time writing code in a functional language, so I'd really like some feedback on whether I'm doing things the "functional" way, whether I'm doin...
I created a Java Trie as part of a project someone challenged me to do. I'm not sure that this is the most efficient way to go about producing a Trie, I know that this works but I was hoping someone with some professional experience could enlighten me on anything I might be doing fundamentally wrong. I'm studying compu...
My main DLL is a .Net one that has an async running method and fires an event when it's done: public class LicenceVerifier { private readonly ILicence _licence; private readonly int _programkey; public delegate void LicencedCheckedEventHandler(object sender, LicenceVerifierResultArgs args); public eve...
I would like to heat some feedback on this. I'm coming from a Java background and this is my first program in Scala. I solved Range Minimum Query problem. object Solution { def main(args: Array[String]){ val readInfo = readLine.split(" "); val numberofElements = Integer.parseInt(readInfo(0)) val numberOf...
Something that bothers me a lot when coding is best practice. I am completely self taught and I find it difficult to know whether I am doing things in the 'right way'. Let's say I have a Gridview on a page which displays data from the following list: (from foo in someContext.foobars select foo).ToList Regardless or ho...
I needed a script to import repositories from other Bitbucket accounts to my own Bitbucket account. I have some 250 repositories in my account and I wanted them to move under Team (which is same as Organization in Github). Though Bitbucket has APIs, I couldn't find any API to import, and instead they provide a HTML for...
In my db MySQL, I have a table ranks with many fields, one for each page I want limit access for the user in the menu application with PHP control: <?php if ($row_ranks['padric'] == '1' ) { echo ('<li><a href="padroncini_ric.php">Ricerca</a></li>'); } else { echo ('<li><a href="#" class=...
I split my implementation of this sequence alignment algorithm in three methods. Where NeedlemanWunsch-method makes use of the ScoringFunction and the Traceback methods. Further I decided to go with two matices. One matrix is for the scoring, the second contains data to make the traceback easier. public static int Scor...
I am trying to implement squarelist by using iteration that points to the head element. I've create this iterator class to make my iterator id directional. I just want to see if I implemented it correctly. class iterator : public std::iterator<std::bidirectional_iterator_tag , Object , int> { public: ...
I have this code to edit certain cells in my Excel file using Apache POI, but it is really slow. How can I improved the performance? Ideally I would like to edit 20000 rows in less than one minute. At the moment it does ~100/min. Any suggestions would be great. public static void main(String[] args) throws IOException,...
A question was asked here about reflection and LINQ to entity. I'm trying to modify the code that was presented to fit my needs. Here's what I am trying to accomplish: I'm writing back-end support for a web site that will be able to run reports on data we have. I want to write this as generically as possible so that ...
I have a file that seems to mix encoding in it. It seems like a Unicode encoded file, but the character length string is encoded like a UTF8 or similar. Here is an example: 05 41 00 72 00 69 00 61 00 6C 00 5 A . r . i . a . l . In this example it stores the string like Unicode, using the extra character, but...
I am currently using this C# method to retrieve MAC addresses from a user's computer as a sort of unique identification. It retrieves the MAC address based on the fact that the physical card is connected to the PCI interface. public static string returnMAC() { ManagementObjectSearcher searcher = new ManagementObjec...
I have implemented a method to compute a convex quadrilateral area in R3. The method works fine, but I am having numerical precision problems in the 8th decimal place. Take a look on the method: internal static double GetTriangleArea(double ax, double ay, double az, double bx, double by, double bz, ...
I just want an indication as to whether or not I'm on the right track regarding PHP OOP, at least on a basic level. Positive criticism welcome. P.S. Excuse the visuals of the code. This is how I usually remember code. <html> <?php //Blueprint class Human{ // properties of human private $gender; private...
I've updated code from a couple weeks back so I've come back to get more feedback. The original post can be found over here: Approximating/Sorting groups of dates into buckets /* * @Author: Gowiem * @Date: 2013-12-17 14:21:17 */ var Hist = Hist || {}; // Timeline Utils ////////////////// Hist.TLUtils = (function()...
Recently I started learning programming and I created this program. I've added something to it with every new lesson. How is my code-writing? Do I make mistakes I shouldn't make? The program itself static void Main() { { Console.WriteLine("Select language:\n"); Console.WriteLine("1....
I have a SQL query that returns a recordset with between 2 and 5 million records and I need to write that to a .csv file. I wrote the following procedure and I'm curious to see if there is a better / more efficient way to do this. Dim conn As New OracleConnection() ... Sub DBExecuteQueryWriteToFile(ByVal SQLCommand As ...
I know of BlockingCollection in .net, but this is rather for my understanding of the pattern. Is this implementation correct ? Consumer class Consumer { readonly Queue<int> _q; public Consumer(Queue<int> q) { this._q = q; } public void Consume() { for (int i = 0; i < 10; i++) ...
This code is for Android but I guess anyone can take a chance at it. It does what I want it to do. Just that I am not comfortable with its deep level of nesting and too much of value swapping. Can this be optimized for readability or in compactness? for(int imagenum, imagenum <76, imagenum++){ if (orientation.cont...
For educational purposes I wrote a little piece of code to rotate greyscale images as "low level" as possible, that is, not using any rotate() function, but doing the math. I was wondering if it could be improved in any way, specially in order to achieve better performance. I'm not concerned with the libraries or the p...
This is a variant of the solution posted here, without state creation/destruction penalty. Note that my comment in the original question about the simplification provided by C++11's inherited constructors applies here too, but I have not updated the code in this question accordingly. That is left as an exercise to the ...
I'm currently using the following code to manage calls to WCF services that are unreliable, and or suffer performance load issues due to contention. Right now this code is limited to solving issue with types that return void. It exponentially backs off from a subsequent call from the server, preventing unhelpful "hamme...
I took a training challenge on Codility that checks for the proper nesting of brackets in a string. The brackets to be checked are {,},(,),[,]. I have written the following Java program which passes in O(n) time and space, but I have a feeling that the extra space I use can be reduced. Also I think that there must be a...
Description This code is for 'fighting' two objects against each other. I am normally using it to make my AIs fight each other in one game or another. In case you are wondering: Yes, I am using this in my Tic Tac Toe Ultimate game to determine the skills of the AIs, my TTT Ultimate implementation for the current coding...
This random generator uses cryptographically secure numbers/chars instead of Math.random(). The Javascript code with jQuery works well but I affect clean code ;) It would be great if you could help me to optimize the code (e.g. in speed). (function () { var $length, $result, $new, $chars; $(document).ready(fun...
In a project, I have a lot of HTML forms without validation and I want to add a front end validation, in a quick way. I start looking for a library and I met Parsley.js. It's a good library, but if I decided to use it I would have to modify all the forms in my application. So there is where this code is born. It's for...
For example, suppose in a view class we need to instantiate some UI components and then populate the fields. Something like: var View = function() { this._initUI(); this._populateFields(); }; View.prototype = { _initUI: function() { this.textField = new TextField(); this.comboBox = new Combobox(); }, ...
What is an island? A group of connected 1s forms an island. For example, the below matrix contains 5 islands: {{1, 1, 0, 0, 0}, {0, 1, 0, 0, 1}, {1, 0, 0, 1, 1}, {0, 0, 0, 0, 0}, {1, 0, 1, 0, 1}} I'm looking for code review, best practices, optimizations etc. public final class CountIslands { private CountIsl...
I'm still at a very beginner level and I'm constantly working on small things to try and develop my skills. I'm hoping someone could just give me a quick review if there's anything obviously horrible about the code from my main PHP class. It's not feature-complete, but I'm hoping at this point I should be able to get a...
I'd like to see how I can improve this code, as I know it's bad practice to have cell reuse identifiers like this, but I could not find any other way to keep the cells that contain images from calling the server again instead of reading the cached image. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRo...
Trying to get an understanding of proper unit testing, I've read up quite a bit and found myself writing tests like the ones that follow. Based on "best practices" etc., how am I doing as far as naming the tests, ensuring that each test is correctly limited in what it does, and providing good test coverage? Following t...
I have a class called Machine. It contains a list of parts and a list of actions. The list of parts will contain instances of the Part class subclasses and the list of actions will contain instances of my Action class subclasses. Each Part subclass will have its corresponding Action subclass. None of the subclasses are...
I have a condition in my code where I need to put a lot of nested else if statements. However, I have managed to reduce some if cases by applying ternary operator, so that code looks nice and is readable. But still I am not satisfied with the result. I would like to remove rest of the if cases too and make the code be...
I tried to check if my vector struct is normalized, and I ended up with this code: public bool IsNormalized { get { double len = Length; // Math.Sqrt ((X * X) + (Y * Y) + (Z * Z)); -- X, Y, Z are in double format const double min = 1 - 1e-14; const double max = 1 + 1e-14; retur...
Is this bad practice? Also, how can it be improved? #!/usr/bin/env bash RUBY_VERSION=2.1.0 printf "Installing Ruby $RUBY_VERSION\\n" if [ -d ruby_build ]; then rm -Rf ruby_build fi if [[ `command -v ruby` && `ruby --version | colrm 11` == "ruby $RUBY_VERSION" ]] ; then echo "You already have this version of...
I'm trying to model a puzzle in order to resolve it with the Choco solver. One of the constraint I'm coding is cyclical (it's triplet which follow themselves) like the following example: s.post(LogicalConstraintFactory.ifThen( IntConstraintFactory.member(mvt[i], new int[]{1, 2, 3}), IntConstraintFactory.not_mem...
This one time pad encryption program I have written (basically just an XOR "encryption" program) seems to be working fine, compiling nicely (gcc -o ./OTP.c), and doing what it's supposed to. However I would like to improve it as much as possible which is why I am posting this. I am particularly insecure about the memor...
I'm trying to implement a system of restricted access. Right now I'm focusing on the "session fixation". I am concerned about the following aspects: Control of a "fingerprint" of the user created by mixing UserAgent, IPAddress and a salt key. If the fingerprint were to change, destroy the user's session. Using the sam...
My domain model consists mostly of simple DTOs, i.e. 'Data Transfer Objects' which this article distinguishes from 'Plain Old C# Objects', like this one: public class Settings { public bool FullScreen = false; public int WindowWidth = 800; public int WindowHeight = 600; } I realize this model is "anemic," ...
I have the following class: MyProtocolClass.h #import <Foundation/Foundation.h> @protocol MyExampleProtocol <NSObject> @required - (void)someRequiredMethod:(NSInteger)someValue; @end @interface MyProtocolClass : UIView // interface stuff @end MyProtocolClass.m #import "MyProtocolClass.h" @interface MyProtocolCla...
I've solved Project Euler #15 in Haskell, but I feel like there might be a better way to express my solution that I'm not seeing. I start out defining my types: import qualified Data.Map.Strict as Map import Data.List data Position = Position Int Int deriving (Show, Eq, Ord) start :: Position start = ...
In particular, if someone could describe a better way to go from the tokenized list to the Expression tree, it would be super helpful. I would like to get rid of the casting in the parser but am not sure how. Full code here package org.bws.calc; import java.util.ArrayList; import org.bws.calc.exception.ParseExceptio...
For class, I had to use Java to draw a triangle and some concentric circles: import javax.swing.*; import java.awt.*; import java.awt.geom.*; public class JComponentDemo { private static final JComponent triangleComponent = new JComponent() { private static final long serialVersionUID = 1L; @Over...
I have two registration paths in my app. They are very similar and I am curious if I should simplify 4 associated actions down into two actions that handle the same amount of work. Here are my controller actions: def employer_registration @employer_signup = EmployerSignup.new end def employee_registration @employe...
As C# doesn't have generic specialisation like C++ template specialisation and I wanted a way to be able to do it, I came up with a little hack that goes a bit like this: public sealed class Specialisation<T> { private Specialisation() { } private static Specialisation<T> instance = new Specia...
The application I'm building can accept two types of updates: Application Update and Parameter Updates. If there is an application update, then parameter updates can be ignored. This is the code that I've written, and it's messy. How can I clean this up? mContext = this.getApplicationContext(); //experimental(); //che...
It was a part of my coding challenge and the last one, but I failed because it failed to yield a result in two seconds for some of sample inputs (out of six samples, three passed but three failed for not meeting the time constraint). Basically, you are supposed to find the maximum deviation from given number of conse...
I'm an intensive user of AWS EC2 instances, many instances are launched, stopped, repurposed, etc. To connect to any instance using SSH I must keep track of their IPs. The bash script I wrote (following the question I asked on SO) uses aws-cli to do the heavy lifting for me, leaving me to remember only the logical name...
After asking a similar question on Stack Overflow, I'm picking up on the answer there to improve my monad. I'm not trying to solve the general case, just come up with one to see how it works. If I'm right, then I really like this pattern. I've already used it to rework some code I'm working on. So I hope it's right. I...
I have a interface with the following implementation public abstract class PersonInterface { public abstract void Update(PersonModel person); public abstract void Delete(int id); public virtual PersonModel Find(int id) { return new List<PersonModel>().Find(x => x.Id == id); ...
In my first iterative algorithm, I do this for (auto &widget : controls.getWidgets()) { if (!widget->visible) continue; widget->draw(); for (auto &widget_component : widget->components) { if (!widget_component->visible) continue; widget_component->draw(); for (auto &ww : widg...
This is Part 1 of a question about performance and general best practices. Part 2 is located here. The body of the messages are the same to illustrate their similarity, the difference is the code provided. This one provides the data the text template utilizes, the other provides the logic to generate the code. The ...
I have this code I am using in a private project. The following is a snippet of code I use to retrieve and load playlists from YouTube: for (feedEntry in a.feed.entry) { if (a.feed.entry.hasOwnProperty(feedEntry)) { feedTitle = a.feed.entry[feedEntry].title.$t.replace('] - ', ']').replace(' : ', '').replace(/\(.*?...
I am writing my own tooltip plugin for my portfolio website that I am currently working on. It works rather well, however, I feel that there is a lot I could improve. This is one of my bigger jQuery plugins that I have written. (function($) { // Used as a template for addTooltip() var tooltipDefaults = { 'class'...
I would like to know whether I'm going in a correct way or not in building my Poker game. So far, I've implemented card and deck classes and I would like to see your feedback about my work. Feel free to criticize the code of any regard (organization, order, comments ... etc) card.h #ifndef CARD_H #define CARD_H #i...
I've written a List monad as an example for a related question. This is a rather frustrating experience as I wanted to use Java, which (as of Java 7) still lacks lambda expressions and lacks higher-order type parameters, which is one reason why this interface Monad<A, I<A> extends Monad<A, I<A>>> { public static I<...
I have some JavaScript code that allows users to select a plan which triggers the second select box to populate with options. The code works, however, it seems to be very inefficient. Any advice on improving the efficiency? JavaScript: var term = 0; var price = 0; var additional = 0; var fix = 0; var plan = document....
I'm new to programming and also to Java and working on problems in Intro to Java by Robert Sedgewick. Here is my question: Connect Four: Given an N-by-N grid with each cell either occupied by an 'X', an 'O', or empty, write a program to find the longest sequence of consecutive 'X's either horizontal, vertically, ...
I have a population (Pop) which has an attribute which is a list of individuals (Ind) where each individual has an attribute which is a list of chromosomes (Chromo). Each chromosome is a list of numbers which tells about the fitness (=reproductive success, the fitness is obtain by multiplying all numbers of a all chrom...
types = [ { name: "Feature"} { name: "Enhancement"} { name: "Bug"} { name: "Spike"} ] buildIndex = (source, property) -> array = [] array[prop[property]] = prop for prop in source array buildIndex types, 'name' Result: [Feature: Object, Enhancement: Object, Bug: Object, Spike: Object] Bug: ...
I'm currently creating a ASP.NET MVC page in C#. I want to hide everything regarding the creation of our "models" and "viewmodels". I have seen much of the fancy stuff regarding Dependency Injection as well as Action Filters, Custom Controllers and so on! But the people I work with are pretty new to this so I want it ...
Some time ago I started with a small Ruby project. I call it social_aggregator. This software aggregates information from different networks to one xml-stream, which you can reuse. For instance on your personal website to show some of your activity to your audience or as your personal news feed. I've a built in Webric...
Some time ago I started with a small Ruby project. I call it social_aggregator. This software aggregates information from different networks to one xml-stream, which you can reuse. For instance on your personal website to show some of your activity to your audience or as your personal news feed. I've written something...
I have made a method which takes two parameters: the value to convert and the base. Based upon those two parameters my method is adjusted (with several helper methods) to change the desired decimal number to a number with a different base. Is this code practical and clean? If not, what should I change to make it better...
I had a small technical C# task using SOLID principle and TDD. But I failed to prove my coding skill through the test. Can anyone offer any small advice for me? I am really eager to learn what my faults are and how I can improve. The interview question is here, and my answer is here. I just reference here some pieces o...
An N-Drome is a string that is the same forwards and backwards when split into n-character units. For example, a string would be a 1-drome if and only if it were a standard palindrome. An example of a 2-drome would be abcdab since its 2-character units are ab, cd, and ab, and its first and last 2-character units are...
Implemented iterator for a binary tree and "pre" "in" and "post" order flavors. I'm looking for code review, best practices, optimizations etc. public class IterateBinaryTree<E> { private TreeNode<E> root; /** * Takes in a BFS representation of a tree, and converts it into a tree. * here the left an...
This is a programming practice that our teacher gave us, and I would appreciate if someone can look over my program and tell me if I did a good job. Basically, the context is I joined a company and am supposed to write a program in C that takes three inputs (ft of steel, number of ball bearings, and lbs of bronze), and...
This program connects all nodes of the binary tree at the same level. A node of a tree contains a left, right and a sibling pointer which would connect it to the next node at the same level. This connection is from left to to right. Example: consider a binary tree with parent as node A and left and right child as node ...
Are these classes properly guarded for thread safety? Do you see any issues with any of the classes? @ThreadSafe public class RetirementAccount { public static final int TYPE1 = 0; public static final int TYPE2 = 1; @GuardedBy("this") private final int accountType; @GuardedBy("buySell") p...
I haven't been able to find an existing tool that does this, so I'm attempting to create one. If anyone knows of one that already exists, I'd appreciate a pointer to it. I plan on using this primarily for cleaning up old backup copies and was hoping for a review of its correctness or suggestions for improvement. Part o...
I have a method that returns a list from a HTML page: private List<HtmlNodes> GetRelevantNodes(HtmlDocument aHtmlDoc, string aID) { List<HtmlNode> nodes = new List<HtmlNode>(); HtmlNode currentDiv = aHtmlDoc.GetElementbyId(aID); if (currentDiv == null) return null; else //Do stu...
I have a concept based polymorphism example listed below. I allow the user to provide any type that implements the draw method and then I add it into a vector of unique_ptr to concept base. If I have a pointer or reference I want to be able to deal with that even though the solution has value semantics in mind. I thus ...
After watching Raymond Hettingers talk Transforming Code into Beautiful, Idiomatic Python I got back to a function I wrote. I'm not quite sure how to make it more pythonic but I think this might be a use-case to use the map function. import logging import string import os def _mounted_drives(possible_device_letters=st...
A bowling score calculator is my go-to exercise for learning the basics of a language. I recently had to pick up Perl so I did this. I'm concerned that I'm doing subroutines wrong. I had a hard time figuring out the syntax for dealing with arguments and what exactly @_ is. I'm just looking for feedback on any egregious...
I have fairly simple collision checking and handling Python code which is currently bottlenecking my performance quite a bit. I haven't done too much coding in python and I'm quite sure there's something that could be done better: Assuming I read this profiler correctly, get_nearby_entities is the biggest culprit. Prof...
I'm doing a program for a course in school (intro software development) and I'm looking for some general feedback as well as any ways this bit of code could be cleaner. I'm also wondering if it is bad practice to use %= as I've talked with some people and have been told it's not good to use any operators like that, oth...
I am making a simple counter in assembly. It counts to a billion and exits. However, the performance of this is really horrible. A Java application (that does the same) outperforms it by around 10x. How can I optimize this code? include 'include/win32ax.inc' section '.data' Data readable writeable outhandle DD ? ...
I have a class that serves to carry data between my JavaScript evaluation class and the player, via the Bukkit Conversations API, available in full on GitHub (you will need Bukkit and Rhino as libraries (you can just comment out the JNBT code, it's not important), and a Craftbukkit server to run it). I was wondering in...
Any major security risks? And please don't get angry over my novice log system. <?php function makesalt($lg) { $chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()-'; $sz = strlen( $chars ); $str = ''; for( $i = 0; $i < $lg; $i++ ) { $str .= $chars[ rand( 0...
A (long) while ago I set up a file server in my basement running Linux. I am OCD when it comes to backups. I set the server up with (remember, this was a while ago): disk for OS disk for 'valuable' things disk for backups The idea was that if any one disk failed, I could replace things with minimal loss. The OS was s...
How can I improve this code (elegance, best practices, etc)? """ Simple in-memory database as a response to the Thumbtack coding challenge. """ class SimpleDb(object): """ Simple in-memory database as a response to the Thumbtack coding challenge. """ def __init__(self): """ Initialize SimpleDb insta...