Skip to content

Instantly share code, notes, and snippets.

Sylvain Saurel ssaurel

View GitHub Profile
@ssaurel
ssaurel / hexadecimalcolorclock.html
Created Jan 5, 2020
Hexadecimal Color Clock on the SSaurel's Blog
View hexadecimalcolorclock.html
<html>
<head>
<link href="https://fonts.googleapis.com/css?family=Roboto+Condensed&display=swap" rel="stylesheet">
<style>
#hexatime {
width: 300px;
text-align: center;
margin: 0 auto;
margin-top: 500px;
@ssaurel
ssaurel / hexislight.js
Created Jan 5, 2020
hexislight function for the Hexadecimal Color Clock on the SSaurel's Blog
View hexislight.js
function hexislight(color) {
var hex = color.replace('#', '');
var red = parseInt(hex.substr(0, 2), 16);
var green = parseInt(hex.substr(2, 2), 16);
var blue = parseInt(hex.substr(4, 2), 16);
// it is a known formula, nothing magical here
var brightness = ((red * 299) + (green * 587) + (blue * 114)) / 1000;
return brightness > 155;
}
@ssaurel
ssaurel / hexaTime.js
Created Jan 5, 2020
hexaTime function for Hexadecimal Color Clock on the SSaurel's Blog
View hexaTime.js
function hexaTime() {
var date = new Date();
// we convert in the 0 .. 255 range
var seconds = parseInt(date.getSeconds() * 255 / 59);
var minutes = parseInt(date.getMinutes() * 255 / 59);
var hours = parseInt(date.getHours() * 255 / 23);
return "#" + toHex(hours) + toHex(minutes) + toHex(seconds);
}
@ssaurel
ssaurel / ToHex.js
Created Jan 5, 2020
toHex function for Hexadecimal Color Clock on the SSaurel's Blog
View ToHex.js
function toHex(d) {
var hex = ("0" + (Number(d).toString(16))).slice(-2).toUpperCase();
return hex;
}
@ssaurel
ssaurel / hexatime.html
Created Jan 5, 2020
Hexadecimal Color Clock Tutorial on the SSaurel's Blog
View hexatime.html
<html>
<head>
<link href="https://fonts.googleapis.com/css?family=Roboto+Condensed&display=swap"
rel="stylesheet">
<style>
#hexatime {
width: 300px;
text-align: center;
margin: 0 auto;
@ssaurel
ssaurel / MainActivity.java
Created Jan 1, 2020
MainActivity for the Anagram Finder App on SSaurel's Blog
View MainActivity.java
package com.ssaurel.myanagram;
import android.app.Dialog;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import androidx.appcompat.app.AlertDialog;
@ssaurel
ssaurel / LoadWords.java
Created Jan 1, 2020
loadWords method on SSaurel's Blog
View LoadWords.java
private void loadWords() {
new Thread(() -> {
Anagram.loadWords(MainActivity.this);
runOnUiThread(() -> {
validate.setEnabled(Anagram.isLoaded());
});
}).start();
}
@ssaurel
ssaurel / activity_main.xml
Last active Jan 1, 2020
UI for the Anagram Finder App on the SSaurel's Blog
View activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="16dp"
android:orientation="vertical"
tools:context=".MainActivity">
<!-- We add a Dummy layout to prevent EditText to gain focus -->
@ssaurel
ssaurel / Anagram.java
Last active Jan 1, 2020
Anagram class for Anagram Finder application on the SSaurel's Blog
View Anagram.java
package com.ssaurel.myanagram;
import android.content.Context;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@ssaurel
ssaurel / SameLetters.java
Created Jan 1, 2020
sameLetters method for the Anagram Finder tutorial on the SSaurel's Blog
View SameLetters.java
// Method for comparing two strings and returning true if they have same letters
public static boolean sameLetters(String a, String b) {
if (a == null)
return b == null;
if (b == null)
return false;
char[] left = a.toCharArray();
char[] right = b.toCharArray();
You can’t perform that action at this time.