Skip to content

Instantly share code, notes, and snippets.

View niorad's full-sized avatar
🏠
Working from home

Antonio Radovcic niorad

🏠
Working from home
View GitHub Profile
@niorad
niorad / server.go
Created May 17, 2023 08:17
Simple Golang-Server for serving Godot-Web-Exports locally (Needed for Godot 4.0)
package main
import (
"fmt"
"log"
"net/http"
)
func main() {
fs := http.FileServer(http.Dir("./"))
@niorad
niorad / skewbacca_poc.swift
Created January 1, 2019 15:55
Swift Core Image Perspective Correction POC
import Cocoa
let context = CIContext()
let lidimg = NSImage(named: "lid")?.cgImage(forProposedRect: nil, context: nil, hints: nil)
let originalCIImage = CIImage(cgImage: lidimg!)
func perspFilter(_ input: CIImage) -> CIImage?
@niorad
niorad / iban_grouping.js
Created March 8, 2018 13:50
Automatic grouping of Iban-Numbers, supporting Backspace- and Del-Keys.
// <input type="text" id="iban">
document.getElementById('iban').addEventListener('input', function (e) {
var target = e.target, position = target.selectionEnd, length = target.value.length;
target.value = target.value.replace(/[^\dA-Za-z]/g, '').replace(/(.{4})/g, '$1 ').trim();
if(e.inputType === 'deleteContentForward') {
target.selectionEnd = position += ((target.value.charAt(position) === ' ') ? 1 : 0);
} else {
target.selectionEnd = position += ((target.value.charAt(position - 1) === ' ' && target.value.charAt(length - 1) === ' ' && length !== target.value.length) ? 1 : 0);
if(target.selectionEnd % 5 === 0) {
@niorad
niorad / history.html
Created February 15, 2018 14:20
Changing Forms with Browser History push/pop
<html>
<head>
<title>Browser-History Push/Pop</title>
</head>
<body>
<form id="myform">
<label>
@niorad
niorad / json-to-struct.go
Last active September 16, 2017 12:21
Simple JSON-to-Struct-Example in Golang
package main
import (
"encoding/json"
"fmt"
)
type Fleet struct {
Cars []Car
Countries []string
'use strict'; // avoid ambiguity and sloppy errors
/**
* Tests whether or not a given string is a Palindrome
* @param {string} stringToTest - the string to test.
*/
function isPalindrome(stringToTest) {
var start = 0,
end;
@niorad
niorad / uiViewToPhotoLibrary.swift
Created April 22, 2016 06:34
Save UIView in User's Photo-Library
UIGraphicsBeginImageContextWithOptions(myView.bounds.size, true, 0)
myUiView.drawViewHierarchyInRect(myView.bounds, afterScreenUpdates: true)
let myImage = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
UIImageWriteToSavedPhotosAlbum(myImage, nil, nil, nil)
@niorad
niorad / minimal_jquery_accordion.js
Created April 20, 2016 18:47
Minimal jQuery-Accordion
$('[data-accordion-toggler]').on("click", function () {
$(this).next().toggle();
$('[data-toggle-content]').not($(this).next()).hide();
});
@niorad
niorad / lazyload.html
Created January 30, 2016 17:16
Short Vanilla-JS Image LazyLoading
<img src="" data-src="myphoto.jpg" class="js-lazyload" alt="Photo">
<noscript>
<img src="myphoto.jpg" alt="Photo">
</noscript>
<script>
var images = document.getElementsByClassName("js-lazyload");
for(var i = 0; i < images.length; i++) {
images[i].attributes.src.value = images[i].attributes["data-src"].value;
@niorad
niorad / diagonalline.scss
Created January 29, 2016 13:41
A diagonal line through a box
.container {
position: relative;
overflow: hidden;
&:after {
position: absolute;
content: ' ';
width: 100%;