Skip to content

Instantly share code, notes, and snippets.

@pasmat
pasmat / mineways-fix.py
Created June 5, 2018 17:58
Fix MineWays white textures/alpha for blender
'''
This script goes through every textureSlot setting settings such that the blocks are rendered correctly in the scene
beware, this sets those properties for ALL objects, so this script should when theres only the world on the scene
also, I've only programmed in python for blender scripting, so the code may be substandard for other pythonists out there
'''
import bpy
objects = bpy.data.objects
@pasmat
pasmat / Boxer.java
Created August 22, 2018 14:25
Data-binded values that are boxed(such as ones that come from Kotlin, as there's no primitive types in Kotlin..) requires safe unboxing, so there's no NPE(null pointer exception) when binding data. Theres a method for this safeUnbox inside Android SDK, however this doesn't support two-way data binding. Therefore we have to define these two-way s…
package fi.matalamaki.util;
import androidx.databinding.InverseMethod;
/**
* Data-binded values that are boxed(such as ones that come from Kotlin,
* as there's no primitive types in Kotlin..) requires safe unboxing,
* so there's no NPE(null pointer exception) when binding data.
*
* Theres a method for this safeUnbox inside Android SDK,
@pasmat
pasmat / DateIntervalToSQL.php
Created January 23, 2019 10:43
turn php DateInterval object to SQL date interval calculation by generating SQL code that adds or subtracts given dateinterval from a variable
/**
* turn php DateInterval object to SQL date interval calculation
* by generating SQL code that adds or subtracts given dateinterval
* from a variable
*
* @param DateInterval $interval the interval to subtract or add
* @param $sqlVariable the variable on which the calculation should be performed on, probably now() or some column
* @param string $sqlFunction the function to use to calculate the date, probably either DATE_SUB or DATE_ADD
* @return string sql time calculation
*/
@pasmat
pasmat / changeUrlParameters.php
Created November 30, 2019 10:53
An function to modify parameters within url, either to change them or replace them. Useful when doing dynamic redirects based on current url.
<?php
static function changeParameters($url, $parameters)
{
$urlParts = parse_url($url);
$url = "";
if (isset($urlParts['scheme'])) {
$url .= $urlParts['scheme'] . "://";
@pasmat
pasmat / changeUrlParameters.js
Created November 30, 2019 10:54
An function to modify parameters within url, either to change them or replace them. Useful when updating url based on changes on page dynamically without a reload.
static function changeParameters($url, $parameters)
{
$urlParts = parse_url($url);
$url = "";
if (isset($urlParts['scheme'])) {
$url .= $urlParts['scheme'] . "://";
}
@pasmat
pasmat / ISO639-2_to_date_format.json
Created January 30, 2020 17:05
Map of countries with their preferred date formats based on ISO629-2 country code adopted from https://gist.github.com/mlconnor/1887156
{
"AL": "yyyy-MM-dd",
"AE": "dd/MM/yyyy",
"AR": "dd/MM/yyyy",
"AU": "d/MM/yyyy",
"AT": "dd.MM.yyyy",
"BE": "d/MM/yyyy",
"BG": "yyyy-M-d",
"BH": "dd/MM/yyyy",
"BA": "yyyy-MM-dd",
@pasmat
pasmat / pausePromise.js
Created January 31, 2020 12:33
a javascript function that returns a Promise which includes artificial latency of x seconds.
/*
used such as..
fetch("https://google.com")
.then(function (response) {
return pausePromise(response, 5)
})
.then(function (response) {
console.log(response);
@pasmat
pasmat / js-css-circle-progress.html
Last active March 3, 2020 21:06
Circular progress using CSS and JS.
<html>
<body>
<style>
.root {
width: 50px;
height: 50px;
position: relative;
}
@pasmat
pasmat / coordinates_by_country_code.json
Created July 13, 2020 13:17
Coordinates and name by country code - found all kind of formats, but not this particular.. Useful for quick lookups of coordinates by country code.
{"AD":{"lat":42.546245,"lng":1.601554,"name":"Andorra"},"AE":{"lat":23.424076,"lng":53.847818,"name":"United Arab Emirates"},"AF":{"lat":33.93911,"lng":67.709953,"name":"Afghanistan"},"AG":{"lat":17.060816,"lng":-61.796428,"name":"Antigua and Barbuda"},"AI":{"lat":18.220554,"lng":-63.068615,"name":"Anguilla"},"AL":{"lat":41.153332,"lng":20.168331,"name":"Albania"},"AM":{"lat":40.069099,"lng":45.038189,"name":"Armenia"},"AN":{"lat":12.226079,"lng":-69.060087,"name":"Netherlands Antilles"},"AO":{"lat":-11.202692,"lng":17.873887,"name":"Angola"},"AQ":{"lat":-75.250973,"lng":-0.071389,"name":"Antarctica"},"AR":{"lat":-38.416097,"lng":-63.616672,"name":"Argentina"},"AS":{"lat":-14.270972,"lng":-170.132217,"name":"American Samoa"},"AT":{"lat":47.516231,"lng":14.550072,"name":"Austria"},"AU":{"lat":-25.274398,"lng":133.775136,"name":"Australia"},"AW":{"lat":12.52111,"lng":-69.968338,"name":"Aruba"},"AZ":{"lat":40.143105,"lng":47.576927,"name":"Azerbaijan"},"BA":{"lat":43.915886,"lng":17.679076,"name":"Bosnia and Her
@pasmat
pasmat / manage_url_parameters.js
Created October 12, 2020 14:08
Functions to manage url parameters from JavaScript context
function parseUrlParameters(search) {
var queryParts = {};
var searchParts = search.split("&");
for (var i = 0; i < searchParts.length; i++) {
var searchPart = searchParts[i];
var whitespaceIndex = searchPart.indexOf("=");