Skip to content

Instantly share code, notes, and snippets.

Emil Hernvall EmilHernvall

Block or report user

Report or block EmilHernvall

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View proof.md

Keybase proof

I hereby claim:

  • I am EmilHernvall on github.
  • I am aderyn (https://keybase.io/aderyn) on keybase.
  • I have a public key whose fingerprint is 5B7E 106F 7A1F B3B2 8236 78E1 398A 0566 9E87 493F

To claim this, I am signing this object:

@EmilHernvall
EmilHernvall / analyzewav.c
Created May 3, 2011
Simple experiment with parsing wav-files
View analyzewav.c
#include <stdio.h>
#include <stdlib.h>
#define FormatID 'fmt ' /* chunkID for Format Chunk. NOTE: There is a space at the end of this ID. */
struct GlobalFormat {
unsigned int id;
unsigned int size;
unsigned int type;
};
@EmilHernvall
EmilHernvall / digitsum.c
Created May 3, 2011
Simple mathematical approach for summing the digits in a number
View digitsum.c
#include <stdio.h>
#include <math.h>
/*
The algorithm is:
d_i = (c mod 10^(i+1)) / 10^i
S = sum_{i=0}^{floor(log_10(c))+1} d_i = sum_{i=0}^{floor(log_10(c))+1} (c mod 10^(i+1)) / 10^i
Where c is the number in question, d_i is the digit at position i counted from the least significant digit
and S is the sum of the digits in the number.
@EmilHernvall
EmilHernvall / expand.c
Created May 3, 2011
Experiment with interpolating strings
View expand.c
#include <stdio.h>
#include <stdlib.h>
int expand(char *target, int size, char *format, char **params, int count)
{
int i, placeholders = 0;
for (i = 0; i < strlen(format); i++) {
if (format[i] == '?') {
placeholders++;
}
@EmilHernvall
EmilHernvall / explode.c
Created May 3, 2011
A somewhat misguided c-implementation of the common split()-function present in most languages
View explode.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int explode(char*** ret, char* instr, char* delim)
{
char* str = strdup(instr);
char** arr = (char**)malloc(sizeof(char*) * (strlen(instr)+1));
int count = 0;
@EmilHernvall
EmilHernvall / perm.c
Created May 3, 2011
setuid to another user and give group members write permissionto files with certain extensions. No idea why I ever needed this.
View perm.c
// perm.c - setuid to another user and give group members write permission
// to files with certain extensions.
// Emil Hernvall, 2008-04-14
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <dirent.h>
#include <string.h>
@EmilHernvall
EmilHernvall / genprimes2.c
Created May 3, 2011
Translation of someone elses code for a more sophisticated prime sieve
View genprimes2.c
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main(int argc, char** argv)
{
if (argc != 2) {
printf("usage: genprimes2 num\n");
return 0;
}
@EmilHernvall
EmilHernvall / binutils.py
Created May 3, 2011
Some small python functions for converting between binary and denary
View binutils.py
def Denary2Binary(n):
'''convert denary integer n to binary string bStr'''
bStr = ''
if n < 0: raise ValueError, "must be a positive integer"
if n == 0: return '0'
while n > 0:
bStr = str(n % 2) + bStr
n = n >> 1
return bStr
@EmilHernvall
EmilHernvall / WordTrainer.java
Created May 3, 2011
A tiny java-program for language training
View WordTrainer.java
/**
* WordTrainer 2008-12-02
* Simple language training in Java. This program accepts text-files
* containing where each line contains two words in two diffrent languages
* separated by a comma (,). The first line follows the same format but
* specifies the language.
*
* Sample gloss-file:
* Engelska,Svenska
* cloud,moln
@EmilHernvall
EmilHernvall / wordcount.c
Created May 3, 2011
Find the most popular words in a file - Linked list and merge sort based version
View wordcount.c
// this has hacky support for swedish characters in utf8.
// i do not recommend this solution for any serious purposes. :)
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <wchar.h>
// convert a twobyte utf8 character into a single integer
#define MB(str) (((str[0] & 0xFF) << 8) | (str[1] & 0xFF))
You can’t perform that action at this time.