Skip to content

Instantly share code, notes, and snippets.

@peanutbother
peanutbother / main.rs
Last active March 31, 2023 20:29
Rustdoc proc_macro_attribute which adds boilerplate for a doctest
/// This struct shows an example
///
/// # Example
#[doc_add_boilerplate(
/// # // you can use hidden lines
/// MyStruct::greet(); // this line is visible
)]
struct MyStruct;
@peanutbother
peanutbother / leapjs.d.ts
Created May 4, 2022 18:56
leapjs typings
declare module "leapjs" {
/**
* When creating a Controller object, you may optionally pass in options
* to set the host , set the port, or select the frame event type.
*
* ```javascript
* var controller = new Leap.Controller({
* host: '127.0.0.1',
* port: 6437,
* frameEventName: 'animationFrame'
package com.example.util;
import com.example.ui.GameMenuModel;
import org.mini2Dx.core.Graphics;
import org.mini2Dx.core.Mdx;
import org.mini2Dx.core.assets.AssetManager;
import org.mini2Dx.core.game.GameContainer;
import org.mini2Dx.core.graphics.viewport.FitViewport;
import org.mini2Dx.core.graphics.viewport.Viewport;
import org.mini2Dx.core.screen.GameScreen;
#!/bin/bash
<< ////
The script creates 'licenses' under '$ANDROID_HOME' and creates a file which proves
that the SDK license was accepted by the user.
Please copy this to your own account/gist/server. Every time there's an updated license, update the file with the new
license hash.
Legally if you run this script (or your own version of it), it means YOU accepted the license - don't trust someone else.
The hashes below are supposed to be taken from $ANDROID_HOME/licenses/android-sdk-license on YOUR machine, after you
@peanutbother
peanutbother / Game.java
Created April 6, 2020 13:08
Bind UI to Model class
package com.myapp;
import com.myapp.util.UiLoader;
import org.mini2Dx.core.Graphics;
import org.mini2Dx.core.assets.AssetManager;
import org.mini2Dx.core.files.*;
import org.mini2Dx.core.game.GameContainer;
import org.mini2Dx.core.graphics.viewport.FitViewport;
import org.mini2Dx.core.graphics.viewport.Viewport;
import org.mini2Dx.ui.UiContainer;
@peanutbother
peanutbother / GameContainer.java
Created April 2, 2020 16:59
UiContainer with xml asset loading
package com.mygame.util;
import org.mini2Dx.core.Graphics;
import org.mini2Dx.core.assets.AssetManager;
import org.mini2Dx.core.files.*;
import org.mini2Dx.core.game.BasicGame;
import org.mini2Dx.core.graphics.viewport.FitViewport;
import org.mini2Dx.core.graphics.viewport.Viewport;
import org.mini2Dx.ui.UiThemeLoader;
import org.mini2Dx.ui.element.Container;
@peanutbother
peanutbother / README.MD
Created October 29, 2019 12:39
Wrap Typescript Types

Example How To Wrap All Properties In Interface Or Tuple

This example shows how to wrap all properties of an interface or tuple dynamically with a wrapper type. This is possible by declaring a dynamic index with a key variable which maps property keys with the original type and using this key to refer to the wrapped type property.

The second example is more dynamic by providing a type descriptor T which provides the wrapper type which then receives the keys and types of the wrapped type.

@peanutbother
peanutbother / hash.js
Last active April 10, 2018 15:10
hash string in format `#HASH~HASH_firstChar.HASH_lastChar`
const hash= (str = "") => {
let _hash = (str) =>
str.split('').reduce((prevHash, currVal) =>
(((prevHash << 5) - prevHash) + currVal.charCodeAt(0))|0, 0);
return `#${str.length > 3?_hash(str.slice(1,-1)):_hash(str)}~${_hash(str.charAt(0))}.${_hash(str.charAt(str.length-1))}`
}
// ~ minified ~
const hash=(t="")=>{let e=t=>t.split("").reduce((t,e)=>(t<<5)-t+e.charCodeAt(0)|0,0);return`#${t.length>3?e(t.slice(1,-1)):e(t)}~${e(t.charAt(0))}.${e(t.charAt(t.length-1))}`};
@peanutbother
peanutbother / lambda_test
Created October 21, 2016 13:52
This mocha test checks usage of lambda in certain scenarios: type-equality, constructor, object-context
var assert = require('assert');
describe('Lambda', function() {
describe('function(){}', function() {
it('should equal function´s type', function() {
var lambda = ()=>{};
var funct = function(){};
assert.equal(typeof(lambda), typeof(funct));
});
@peanutbother
peanutbother / console.log.disable.js
Created July 25, 2016 23:02
Disable console.log for on website
// backup console object
var debug = console;
//create Console Class
var Console;
(Console = function (showError) {
if (typeof showError == 'boolean') {
this.showError = showError;
}
}).prototype = {
showError: false;