Skip to content

Instantly share code, notes, and snippets.

View metalmatze's full-sized avatar
🤘

Matthias Loibl metalmatze

🤘
View GitHub Profile
@metalmatze
metalmatze / machine-accuracy.php
Created February 10, 2014 11:40
This little script calculates lower numbers until there is no difference for the machine
<?php
$difference = 1.0;
$i = 0;
while(1.0 + $difference != 1.0)
{
if ($i % 5 == 0)
printf("%4.0f | %16.8e | unequal 1\n", $i, $difference);
@metalmatze
metalmatze / machine-accuracy.rb
Created February 13, 2014 09:13
This little ruby script calculates lower numbers until there is no difference for the machine
difference = 1
i = 0
while 1 + difference != 1
puts "#{i} | #{sprintf('%16.8e', difference)} | unequal 1"
difference = difference / 2.0
i += 1
end
@metalmatze
metalmatze / photo.coffee
Created March 4, 2015 18:08
GET image and display base64
$http.get(url, {
headers:
Authorization: 'Bearer ' + authenticationService.getToken()
responseType: 'arraybuffer'
})
.success((data) ->
image = new Image()
reader = new FileReader()
blob = new Blob([data])
@metalmatze
metalmatze / element-name.html
Created May 12, 2015 10:38
Polymer element
<dom-module id="element-name">
<style>
/* CSS rules for your element */
</style>
<template>
<!-- local DOM for your element -->
<div>{{greeting}}</div> <!-- data bindings in local DOM -->
</template>
</dom-module>
render() {
return (
<GoogleMaps
containerProps={{
style: {
height: "100%"
}
}}
ref="map"
@metalmatze
metalmatze / rx-retrofit.java
Created October 22, 2015 23:24
Retrofit returning a observable which is mapped and then copied into the realm Database
Api.with(getActivity()).request()
.authors()
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.map(authorJsonArray -> authorJsonArray.data)
.subscribe(authors -> {
realm.beginTransaction();
realm.copyToRealmOrUpdate(authors);
realm.commitTransaction();
});
package main
import (
"github.com/tucnak/telebot"
"log"
"time"
)
var (
bot *telebot.Bot
@metalmatze
metalmatze / php.php
Created March 21, 2017 19:35
PHP...
<?php
$a = array(1 => 'a', true => 'b', 'c', "2" => 'd', 2 => "e", 0x1 => "g", 2e0 => "h");
echo(count($a));
var_dump($a);
@metalmatze
metalmatze / substract.go
Created April 6, 2017 15:19
What not to do in Go.
// Subtract deals with subtraction of all types of number.
func Subtract(left interface{}, right interface{}) interface{} {
var rleft, rright int64
var fleft, fright float64
var isInt = true
switch left.(type) {
case int:
rleft = int64(left.(int))
case int8:
rleft = int64(left.(int8))
@metalmatze
metalmatze / http.go
Created June 29, 2018 22:39
Run Go as WebAssembly
package main
import (
"fmt"
"net/http"
)
// https://github.com/golang/go/tree/master/misc/wasm
func main() {