Skip to content

Instantly share code, notes, and snippets.

View svagionitis's full-sized avatar

stavros vagionitis svagionitis

View GitHub Profile
@svagionitis
svagionitis / _.md
Last active August 29, 2015 14:17 — forked from klange/_.md

Since this is on Hacker News...

  • No, I don't distribute my résumé like this. A friend of mine made a joke about me being the kind of person who would do this, so I did (the link on that page was added later).
  • I apologize for the use of _t in my types. I spend a lot of time at a level where I can do that; "reserved for system libraries? I am the system libraries".
  • They're all while loops because shut up, you're overthinking a joke.
@svagionitis
svagionitis / perm_digits.c
Last active September 27, 2020 11:59
Permutations of a number with N digits using the Fischer and Krause algorithm.
/**
* @file perm_digits.c
* @author Stavros Vagionitis
* @date 17 Mar 2015
* @brief Calculate the permutations of an N-digit number
* without using an array and using the Fischer and Krause algorithm.
*
*/
#include <stdlib.h>
@svagionitis
svagionitis / odometer.c
Last active September 27, 2020 12:00
Odometer algorithm.
#include <stdlib.h>
#include <stdio.h>
/**
* \brief Compute the exponential power for uint64_t
*
* \param base The base to be expanded.
* \param exp The exponential.
* \return the computed power exponential.
*/
/*
This brute force algorithm was originally written (by me) back in 1998, and has been collecting dust
since then. However, for the purpose of testing Gist on GitHub I decided to rewrite the algorithm
from VB6 to C#, make some improvements and release this fast, compact, non-recursive, brute force
algorithm under the MIT license: http://opensource.org/licenses/MIT
Notes:
- Do a run with testLetters = "0123456789" and testLength = 3, to see what happens
- Remember to keep the callback testCalback as fast as possible
- Tweet some love to @fredrikdev :)
@svagionitis
svagionitis / perm.c
Last active August 29, 2015 14:16
Permutations using the algorithms described http://www.quickperm.org/pseudo2.php
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#define SZ_ARRAY 5
void swap_array(uint64_t arr[], uint64_t i, uint64_t j)
{
arr[i] ^= arr[j];
@svagionitis
svagionitis / getNTPMessage.py
Last active August 29, 2015 14:14
Receive the NTP response
#!/usr/bin/env python
# Based on http://blog.mattcrampton.com/post/88291892461/query-an-ntp-server-from-python
# but added to interprete the message received from the NTP server. The structure of the
# response message described https://www.eecis.udel.edu/~mills/database/rfc/rfc1305/rfc1305c.pdf
# Also check http://www.ntp.org/ntpfaq/NTP-s-algo.htm for information of the NTP algorithm.
# Check the RFC for NTP https://www.ietf.org/rfc/rfc5905.txt
from socket import AF_INET, SOCK_DGRAM
import sys
import socket
import struct, time
@svagionitis
svagionitis / Makefile
Last active September 27, 2020 12:01
Implement the look and say sequence in C. More info about the look and say sequence here http://en.wikipedia.org/wiki/Look-and-say_sequence
all: look_and_say_seq
look_and_say_seq: look_and_say_seq.c
gcc -o look_and_say_seq -O2 -Wall -W -ansi -pedantic -std=gnu99 look_and_say_seq.c
clean:
rm -rf look_and_say_seq

How to set up stress-free SSL on an OS X development machine

One of the best ways to reduce complexity (read: stress) in web development is to minimize the differences between your development and production environments. After being frustrated by attempts to unify the approach to SSL on my local machine and in production, I searched for a workflow that would make the protocol invisible to me between all environments.

Most workflows make the following compromises:

  • Use HTTPS in production but HTTP locally. This is annoying because it makes the environments inconsistent, and the protocol choices leak up into the stack. For example, your web application needs to understand the underlying protocol when using the secure flag for cookies. If you don't get this right, your HTTP development server won't be able to read the cookies it writes, or worse, your HTTPS production server could pass sensitive cookies over an insecure connection.

  • Use production SSL certificates locally. This is annoying

Transforming Code into Beautiful, Idiomatic Python

Notes from Raymond Hettinger's talk at pycon US 2013 video, slides.

The code examples and direct quotes are all from Raymond's talk. I've reproduced them here for my own edification and the hopes that others will find them as handy as I have!

Looping over a range of numbers

for i in [0, 1, 2, 3, 4, 5]:
greek_alphabet = {
u'\u0391': 'Alpha',
u'\u0392': 'Beta',
u'\u0393': 'Gamma',
u'\u0394': 'Delta',
u'\u0395': 'Epsilon',
u'\u0396': 'Zeta',
u'\u0397': 'Eta',
u'\u0398': 'Theta',
u'\u0399': 'Iota',