Skip to content

Instantly share code, notes, and snippets.

View drikusroor's full-sized avatar
🏠
Working from anywhere

Drikus Roor drikusroor

🏠
Working from anywhere
  • Utrecht, Netherlands
View GitHub Profile
@drikusroor
drikusroor / SortListOfLists.cs
Created January 19, 2022 11:16
Sort list of lists in dotnet core
using System;
using System.Text.Json;
var array = JsonSerializer.Deserialize<List<List<int>>>("[[3, 2], [1, 1], [0,3],[0,2],[0,1], [1,3], [1,2], [2, 3]]");
Console.WriteLine(JsonSerializer.Serialize(array));
// [[3,2],[1,1],[0,3],[0,2],[0,1],[1,3],[1,2],[2,3]]
var sorted = array.OrderBy(y => y[0]).ThenBy(y => y[1]);
Solidity lets you program on Ethereum, a blockchain-based virtual machine that allows the creation and execution of smart contracts, without needing centralized or trusted parties.
Solidity is a statically typed, contract programming language that has similarities to Javascript and C. Like objects in OOP, each contract contains state variables, functions, and common data types. Contract-specific features include modifier (guard) clauses, event notifiers for listeners, and custom global variables.
Some Ethereum contract examples include crowdfunding, voting, and blind auctions.
As Solidity and Ethereum are under active development, experimental or beta features are explicitly marked, and subject to change. Pull requests welcome.
// First, a simple Bank contract
// Allows deposits, withdrawals, and balance checks
// simple_bank.sol (note .sol extension)
/* **** START EXAMPLE **** */
@drikusroor
drikusroor / cookie-banner.js
Last active December 29, 2021 22:07
Customizable javascript cookie banner
@drikusroor
drikusroor / wordpress-ga-sitetag.php
Last active December 26, 2021 21:52
Insert a Google Analytics sitetag in Wordpress using a constant defined in wp-config.php
<?php
if (defined('GOOGLE_ANALYTICS_KEY')) {
?>
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=<?php echo GOOGLE_ANALYTICS_KEY; ?>"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag() {
dataLayer.push(arguments);
@drikusroor
drikusroor / connection-string-tester.cs
Created December 9, 2021 09:10
Test multiple SQL Server connection strings in a dotnet console app
// Source: https://ainab.site/2021/12/09/test-multiple-sql-server-connection-strings-in-a-dotnet-console-app/
using System.Data.SqlClient;
class Credentials
{
public string Username { get; set; }
public string Password { get; set; }
public string Server { get; set; }
public Credentials(string username, string password, string server = "sql-server.example.com") {
Username = username;
@drikusroor
drikusroor / create-sql-login-user.sql
Last active December 9, 2021 08:28
Create a SQL login, connect a user to it, and add roles to the user
-- Source: https://ainab.site/2021/12/08/create-an-azure-sql-server-login-and-connect-a-user-to-it/
-- Execute this query in the "master" database
-- Create new login
CREATE LOGIN [new-login]
WITH PASSWORD = 'complex-password'
GO
-- Execute these queries in the target database
@drikusroor
drikusroor / add-custom-colors.php
Created November 15, 2021 12:08
Quickly add multiple custom color settings and controls to a Wordpress theme's Customizer
<?php
function my_theme_add_setting_control($wp_customize, $color, $options)
{
$key = $color[0];
$label = $color[1];
$default_hex = $color[2];
$section = $options['section'];
@drikusroor
drikusroor / full-width-embedded-google-maps.php
Last active October 29, 2021 19:05
Easy full-width embedded Google Maps in php
<!-- In PHP -->
<iframe
src="
<?php
$search_terms = rawurlencode("3 Abbey Road, London, GB NW8 9AY");
$src =
"https://www.google.com/maps?q=2880%20" .
$search_terms .
"&t=&z=15&ie=UTF8&iwloc=&output=embed";
echo $src;
@drikusroor
drikusroor / skeleton.scss
Created October 17, 2021 15:22
Simple animated skeleton in Sass & CSS
// Sass
.skeleton {
display: inline-block;
height: 1em;
position: relative;
overflow: hidden;
background-color: #dddbdd;
&::after {
position: absolute;
@drikusroor
drikusroor / upptime-search-bar.js
Last active September 22, 2021 21:01
Script to add a search bar to a Upptime status page
/**
HOW TO USE
Add the minified line of javascript to your .upptimerc.yml configuration file, so that it looks like this:
status-website:
js: "class SearchBar { searchInput = null; constructor() { window.addEventListener('load', this.init.bind(this)); } init() { this.setupElements(); this.addEventListeners(); } setupElements() { this.searchInput = this.createSearchBar(); this.updateSites(); } updateSites() { this.sites = document.querySelectorAll('section.live-status article.link'); } addEventListeners() { this.searchInput.addEventListener( 'input', this.handleSearchInputChange.bind(this) ); } handleSearchInputChange(e) { this.updateSites(); const value = e.target.value; this.sites.forEach((siteEl) => { let match = false; const headingEl = siteEl.querySelector('h4 a'); const heading = headingEl.innerHTML; const href = headingEl.getAttribute('href'); if (!value) { match = true; } else { if (heading.toLowerCase().includes(value.toLowerCase())) { match = true; } else if ( href && href.toLowerCase().includes