Skip to content

Instantly share code, notes, and snippets.

View dahnielson's full-sized avatar

Anders Dahnielson dahnielson

View GitHub Profile
@dahnielson
dahnielson / UUID.php
Last active April 5, 2024 21:14
Pure PHP UUID generator
<?php
/**
* UUID class
*
* The following class generates VALID RFC 4122 COMPLIANT
* Universally Unique IDentifiers (UUID) version 3, 4 and 5.
*
* UUIDs generated validates using OSSP UUID Tool, and output
* for named-based UUIDs are exactly the same. This is a pure
* PHP implementation.
@dahnielson
dahnielson / OpenFileButton.svelte
Last active August 2, 2020 08:49
Open the file dialog in Svelte
<script>
let fileInput
</script>
<style>
input {
display: none;
}
</style>
@dahnielson
dahnielson / lcd.c
Last active July 2, 2018 09:48
I can't work out why this doesn't work properly...
#include "lcd.h"
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <linux/i2c-dev.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/stat.h>
@dahnielson
dahnielson / index.js
Last active May 26, 2018 20:43
Module that works directly in browser and node.js
// Check whether we are in browser or node.js
var _self = (typeof window !== 'undefined') ? window : {};
// Scoping with anonymous closure for browser
var Foo = (function(){
var _ = _self.Foo = {
init: function() {
}
}
@dahnielson
dahnielson / delicious.json
Last active March 14, 2017 19:34
Sitemap for webscraper.io and Python script
{
"startUrl": "https://del.icio.us/<your username>?&page=[1-100]",
"selectors": [{
"parentSelectors": ["_root"],
"type": "SelectorElement",
"multiple": true,
"id": "bookmark",
"selector": "div.articleThumbBlockOuter",
"delay": ""
}, {
@dahnielson
dahnielson / .Xmodmap
Created January 3, 2012 13:18
(Re)map caps lock key to escape
remove Lock = Caps_Lock
keysym Caps_Lock = Escape
@dahnielson
dahnielson / gist:512192
Created August 6, 2010 23:24
Generate salt
<?php
/**
* This function generates a password salt as a string of x characters
* ranging from a-zA-Z0-9.
*
* @param $max integer The number of characters in the string
* @author AfroSoft <scripts@afrosoft.co.cc>
*/
function generate_salt($max = 40)
@dahnielson
dahnielson / combinations.php
Created August 4, 2010 22:10
Get letter combinations
<?php
function filterSign($var)
{
return strlen($var) < 2 ? false : true;
}
function getCombinations($values)
{
$perms = array(null);
@dahnielson
dahnielson / exceptions.md
Created July 29, 2010 11:55
Standard exceptions

Exceptions

  • std::exception
    • std::bad_alloc thrown by new on allocation failure.
    • std::bad_cast thrown by dynamic_cast when fails with a referenced type.
    • std::bad_exception thrown when an exception type doesn't match any catch.
    • std::bad_typeid thrown by typeid.
    • std::logic_error thrown by logic errors, represent problems in the internal logic of a program; in theory, these are preventable, and even detectable
@dahnielson
dahnielson / gist:469501
Created July 9, 2010 14:15
Time accumulator
import pygame
class Time(object):
def __init__(self, uiTimeStep):
"Takes the time step in milliseconds as argument."
self.uiTimeStep = uiTimeStep
self.uiNewTime = 0
self.uiCurrentTime = 0
self.uiTimeAccumulator = 0