Skip to content

Instantly share code, notes, and snippets.

@sapher
sapher / hash-password.js
Created February 21, 2014 13:27
Hashing password with NodeJS
crypto = require('crypto');
//Iterations
iterations = 100;
//Length
length = 32;
/*
Generate the salt
@sapher
sapher / ListExtension.cs
Last active August 29, 2015 14:04
List extension that help split a list into smaller chuncks of n size
using System;
using System.Collections.Generic;
using System.Linq;
namespace Core.Extensions
{
public static class ListExtension
{
public static IEnumerable<IEnumerable<T>> Split<T>(this List<T> list, int size)
{
@sapher
sapher / printf.c
Created September 2, 2014 18:54
Redirect printf for stm32f4 in keil uvision
#include <stdio.h>
#define ITM_Port8(n) (*((volatile unsigned char *)(0xE0000000+4*n)))
#define ITM_Port16(n) (*((volatile unsigned short*)(0xE0000000+4*n)))
#define ITM_Port32(n) (*((volatile unsigned long *)(0xE0000000+4*n)))
#define DEMCR (*((volatile unsigned long *)(0xE000EDFC)))
#define TRCENA 0x01000000
struct __FILE { int handle; /* Add whatever is needed */ };
@sapher
sapher / main.c
Last active August 29, 2015 14:07
Reading of 96bits long Unique ID on STM32F407VG
/* Includes ------------------------------------------------------------------*/
#include <stdio.h>
#include "STM32F4xx.h"
/* Private variables ---------------------------------------------------------*/
struct __FILE { int handle; };
FILE __stdout;
FILE __stdin;
/* Private functions ---------------------------------------------------------*/
@sapher
sapher / sntp-client.c
Last active August 29, 2015 14:07
sntp client with bsd socket (unix)
//Includes
#include <stdio.h>
#include <stdlib.h> // EXIT_xxxxx
#include <string.h> //memset
#include <unistd.h> //close
#include <sys/socket.h>
#include <sys/types.h>
#include <arpa/inet.h>
//SNTP RFC > https://tools.ietf.org/html/rfc4330
@sapher
sapher / map.c
Last active August 29, 2015 14:08
C simple function that map a value from a range to another range
#include <stdio.h>
int map(int value, int fromStart, int fromEnd, int toStart, int toEnd) {
return (value - fromStart) * (toEnd - toStart) / (fromEnd - fromStart) + toStart;
}
int main(void) {
int x = map(50, 0, 100, 0, 255);
@sapher
sapher / pic12f615.c
Created November 13, 2014 12:56
PIC12F615 PWM example on AF pin GP5
#include "xc.h"
#include "config.h"
#define _XTAL_FREQ 8000000
/* Variables */
unsigned int i;
void setDuty(unsigned int duty) {
CCPR1L = duty >> 2;
@sapher
sapher / pic16f1704_usart.c
Last active August 29, 2015 14:09
PIC16F1704 USART TX example (RX is not implemented)
#include "xc.h"
#include "config.h"
#define BUFSIZE 12 //Maximum size of received string
volatile unsigned char rx_data;
volatile unsigned char rx_index;
volatile unsigned char rx_buffer[BUFSIZE];
/**
@sapher
sapher / GNUmakefile
Created January 19, 2015 09:16
GNUMakefile
include $(GNUSTEP_MAKEFILES)/common.make
# make a simple program in Objective-C
TOOL_NAME = App
# The implementation Objective-C file which is going to be compiled
App_OBJC_FILES = main.m
# Header files of your project
#App_HEADER_FILES = xxx.h
# Define compilation flags
ADDITIONAL_CPPFLAGS = -Wall -Wno-import
# Include rules for creating a command line tool for Objective-C
@sapher
sapher / main.m
Created January 19, 2015 09:23
Objective-C - Hello world
#import <Foundation/Foundation.h>
int main (void) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
NSLog(@"Hello World!\n");
[pool release];
return 0;
}