Skip to content

Instantly share code, notes, and snippets.

#include <stdio.h>
#include <stdlib.h>
int main()
{
const size_t size = 1000;
char *line = NULL;
FILE *infile = NULL;
int status = 1; /* assume failure unless everything succeeds */
double a, b, c, sum;
#include <stdio.h>
#include <stdlib.h>
int main()
{
const size_t size = 1000;
char *line;
FILE *infile;
double a, b, c, sum;
for (i=0; i<3; ++i)
{
for (j=0; j<3; ++j)
{
if (a[i][j] < 0)
goto stop_printing;
printf(" %9d", a[i][j]);
}
printf("\n");
}
valid = 1;
for (i=0; i<3; ++i)
{
for (j=0; j<3; ++j)
{
if (a[i][j] < 0)
{
valid = 0;
break;
}
for (i=0; i<3; ++i)
{
for (j=0; j<3; ++j)
{
printf(" %9d", a[i][j]);
}
printf("\n");
}
/* ... remaining code ... */
@cosinekitty
cosinekitty / photogps.py
Created May 9, 2020 21:28
Example of extracting GPS coordinates from a jpeg photograph.
#!/usr/bin/env python3
import sys
import exifread # sudo pip3 install exifread
def GpsEval(v):
factor = 1.0
sum = 0.0
for r in v:
sum += factor * (r.num / r.den)
factor /= 60.0
from enum import IntEnum
class ImageFormat(IntEnum):
PNG = 1
JPEG = 2
GIF = 3
@cosinekitty
cosinekitty / cards4.py
Last active May 9, 2020 01:15
Different enumerated types can have same values, but still be distinct.
from enum import Enum, unique
@unique
class Suit(Enum):
Club = 1
Diamond = 2
Heart = 3
Spade = 4
@unique
def React(suit):
if suit == Suit.Club:
print('Please do not beat me with that.')
elif suit == Suit.Diamond:
print('Now we are rich.')
elif suit == Suit.Heart:
print('I love you too.')
elif suit == Suit.Spade:
print('Thank you for the handy garden tool.')
else:
@unique
class Suit(Enum):
Club = 1
Diamond = 1 # Oops!
Heart = 3
Spade = 4