Skip to content

Instantly share code, notes, and snippets.

View frumbert's full-sized avatar

frumbert frumbert

View GitHub Profile
@njvack
njvack / README.md
Last active February 8, 2024 21:43
Color to hex and rgba converter

Simple canvas-based color converter

To answer this StackOverflow question I wrote this — a small solution based on a never-rendered <canvas> element. It fills a 1-pixel canvas with the provided fill-style, and then reads the RGBA values of that pixel. It will work with any CSS color -- name, rgba(), hex, or even something more exotic like a gradient or pattern. Invalid colors are always returned as transparent black. Transparent colors are treated as painted on a newly-cleared canvas.

It's been tested in modern-ish versions of IE, Chrome, Safari, and Firefox. The API is:

color_convert.to_hex(color)   # Converts color to a hex-based RGB triple; to_hex('red') returns '#ff0000'
color_convert.to_rgba(color)  # Converts color to an rgba() string; to_rgba('red') returns 'rgba(255,0,0,1)'
@mpkliewer
mpkliewer / xapi-storyline-basic-instructions.md
Last active March 12, 2024 09:30
Simple example of pulling xAPI results from LRS in an Articulate Storyline project

Basic Instructions

  1. Copy the Script1 function into the first Storyline JS trigger on the page you wish to display results
    • Repeat for Scripts 2 and 3
    • Tweak as necessary to get different results
  2. Create a Storyline variable to hold the results
    • Just called “storylineVar” in the example
  3. Insert a “reference” to this variable on the screen (%storylineVar%)
  4. Publish
    • Doesn’t have to be “TinCan” publish since we’re handling it ourselves
  5. Add the “tincan.js” library to the root folder of your published output
@pqina
pqina / create-thumbnail.php
Last active January 4, 2025 17:42
Create thumbnails with PHP
<?
// Link image type to correct image loader and saver
// - makes it easier to add additional types later on
// - makes the function easier to read
const IMAGE_HANDLERS = [
IMAGETYPE_JPEG => [
'load' => 'imagecreatefromjpeg',
'save' => 'imagejpeg',
'quality' => 100
@remarkablemark
remarkablemark / draggable-example.js
Created December 17, 2016 04:13
Basic draggable example using vanilla JavaScript.
'use strict';
/**
* Makes an element draggable.
*
* @param {HTMLElement} element - The element.
*/
function draggable(element) {
var isMouseDown = false;
@paceaux
paceaux / attribute-promise.js
Created June 16, 2017 21:11
A promise that can be set on an element, to resolve when that element's attributes have changed
** AttrPromise
* @param {element} DOM element. required
* @param {attributeName} String. Optional. Attribute that is expected to change.
* @param {rejectTime} Int. Optional. Seconds (not ms) to wait before rejecting. 0 means there is no reject time.
* @returns {promise}
*/
function attrPromise(element, attributeName,rejectTime = 0) {
return new Promise((resolve,reject) => {
let hasChanged = false;
@gdestree
gdestree / dnsmasq-setup.md
Created December 18, 2017 19:48
Setup dnsmasq on OS X *updated for .test

Never touch your local /etc/hosts file in OS X again

UPDATED for .test

To setup your computer to work with *.test domains, e.g. project.test, awesome.test and so on, without having to add to your hosts file each time.

Requirements

@Oranzh
Oranzh / AES-256 encryption and decryption in PHP and C#.md
Created March 24, 2018 04:19
AES-256 encryption and decryption in PHP and C#

AES-256 encryption and decryption in PHP and C#

Update: There is a more secure version available. Details

PHP

<?php

$plaintext = 'My secret message 1234';
@nicolasdao
nicolasdao / webpack.md
Last active June 22, 2024 02:56
Basic damn Webpack config for simple transpilation ES6 to ES5

Install

npm install -D acorn babel-loader @babel/core @babel/preset-env babel-polyfill webpack webpack-cli uglifyjs-webpack-plugin --save-dev

webpack-cli and acorn are dependencies that you, unfortunately, have to install if you want to run this god damn thing without any obscure warnings or errors.

Build

Configure Webpack

@TETYYS
TETYYS / brian.md
Last active February 9, 2024 03:44
All Brian TTS characters
Character code (character) Duration (ms) Alias to Pronounced as
27 (�) 656 None Escape
33 (!) 1333 None Exclamation mark
35 (#) 409 None Hash
36 ($) 425 None Dollar
37 (%) 631 None Percent
38 (&) 329 None And
43 (+) 396 None Plus
45 (-) 706 None Dash
@lennardv2
lennardv2 / 1. Building PHP-MAMP on Apple Silicon M1.md
Last active February 25, 2025 15:28
Native PHP development / MAMP stack on Apple silicon M1

Building the MAMP stack (php, apache & mysql) on Apple Silicon ARM (native)

Update! This tutorial is outdated. Nowadays brew installes m1 binaries just fine. Also use valet: https://laravel.com/docs/9.x/valet. It's 10x easier.

In this tutorial, we'll build the the nescessary packages for ARM via homebrew. After that we'll configure apache2 for using virtual hosts. The native php is ofcourse way faster, see the results of this benchmark below.

TEST NAME SECONDS OP/SEC