Although [coding style](w:Coding style "wikilink") might seem a minor thing for novice programmers, it really is of utter importance when writing code for a medium-sized or big project. If you code alone, it still is vital to follow prespecified coding standards in order to achieve a better level of code readability for yourself. If you code as a member of a team, not following strict style conventions is completely out of the question. Considering that a project which you're the only programmer for might grow into a team project in the future makes it a crucial matter to follow certain coding standards, as it is a hard and time-consuming procedure to port code to new coding style. And, although many coding style rules can be automated and applied using a beautifier script, many rules cannot (as they fall into the programmer's judgment), and a lot of rules are broken by these scripts. In addition, many programmers, including myself, do not like using these scripts and believe that using a beautiful
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* An implementation of doubly linked lists in C. | |
* | |
* API: | |
* * init() | |
* Initializes a doubly linked list and returns it. | |
* * push( list, value ) | |
* Appends a new element with value to the list. | |
* * destroy( list, value ) | |
* Destroys the first element with value found in the list. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cstdio> | |
#include <cstdlib> | |
#include <ctime> | |
#include <cassert> | |
int main( int argv, char *argc[] ) { | |
assert( argv > 1 ); | |
const int N = atoi( argc[ 1 ] ); // Password length | |
char i, randChar; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// It only z-orders 8-bit numbers correctly but you can modify | |
// the for loop so that it works for more bits (maybe replace 8 | |
// with 16 or 32, 64 is probably a bad idea unless you have a | |
// 128-bit system) and the return/ret and parameter type accordingly. | |
int zOrder( int lhs, int rhs ) { | |
int bit, ret; | |
for ( ret = 0, bit = 0; bit < 8; ++bit ) { | |
ret |= ( ( ( lhs & 1 ) << 1 ) | ( rhs & 1 ) ) << ( bit << 1 ); | |
lhs >>= 1; | |
rhs >>= 1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding: utf-8 | |
import sys | |
alphabet = { | |
'Α': 'A', | |
'Β': 'B', | |
'Γ': 'G', | |
'Δ': 'D', | |
'Ε': 'E', | |
'Ζ': 'Z', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import operator | |
def compute(expression): | |
fn = { | |
'+': operator.add, | |
'-': operator.sub, | |
'*': operator.mul, | |
'/': operator.div | |
} | |
# could use fn.keys but dictionaries are orderless |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Verifying that +gtklocker is my openname (Bitcoin username). https://onename.com/gtklocker |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var before = +new Date(); | |
console.log("execution took", +new Date() - before, "ms"); | |
// execution took 13 ms |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
execgit() { | |
exec git "$@" | |
} | |
if [ "`git rev-parse --is-inside-work-tree`" != "true" ]; then | |
execgit | |
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
OLD_CASK_PATH="/opt/homebrew-cask/Caskroom" | |
NEW_CASK_PATH="/usr/local/Caskroom" | |
APP_DIRS=( "$HOME/Applications" "/Applications" ) | |
mkdir -p $NEW_CASK_PATH | |
chown -R `whoami`:staff $NEW_CASK_PATH | |
for app_dir in "${APP_DIRS[@]}"; do |
OlderNewer