Skip to content

Instantly share code, notes, and snippets.

View server.js
import WebSocket from 'ws';
const webSocketServer = new WebSocket.Server({ server });
webSocketServer.on('error', (err) => logger.error(err));
webSocketServer.on('headers', (headers) => logger.log('headersi', headers));
webSocketServer.on('connection', (ws) => {
logger.log('new connection');
ws.on('open', () => logger.log('open'));
ws.on('close', () => logger.log('closed'));
ws.on('message', (message) => {
@pohy
pohy / Player.cs
Created Feb 21, 2020
Godot Subnode attribute
View Player.cs
class Player : KinematicBody
{
[Subnode] private Spatial MyNode; // finds subnode called "MyNode" which is a Spatial, crash if not found
[Subnode("custom_name")] private Label MyLabel; // finds a Label called "custom_name"
public override void _Ready()
{
this.FindSubnodes(); // Must write `this.` because it's an extension class
}
}
View basic-raymarching.glsl
#define MAX_STEPS 100
#define MAX_DISTANCE 100.
#define MIN_DISTANCE .01
float getDistance(vec3 point) {
vec4 sphere = vec4(0, 1, 6, 1);
float sphereDistance = length(point - sphere.xyz) - sphere.w;
float planeDistance = point.y;
return min(sphereDistance, planeDistance);
}
@pohy
pohy / init.js
Created Jun 4, 2019
Async mJS RPC Handler
View init.js
load('rpc.js');
let testWiFi = ffi('bool mgos_captive_portal_wifi_setup_test(char*,char*,void(*)(bool,char*,char*,userdata),userdata)');
RPC.addHandlerAsync('ConnectToWifi', function(respond, args) {
if (
typeof args !== 'object'
|| typeof args.ssid !== 'string' || args.ssid.length < 1
|| typeof args.pass !== 'string' || args.pass.length < 1
) {
@pohy
pohy / TaskPresenter.php
Created Nov 21, 2013
Nette example application
View TaskPresenter.php
<?php
use Nette\Application\UI\Form;
class TaskPresenter extends BasePresenter
{
private $listRepository;
private $userRepository;
private $taskRepository;
private $list;
View errors.java
public ValidationResponse createValidationResponse(BindingResult result, boolean translate) {
ValidationResponse response = new ValidationResponse();
if(!result.hasErrors()) {
response.setSuccess(true);
return response;
}
response.setSuccess(false);
Locale locale = LocaleContextHolder.getLocale();
for (FieldError error : result.getFieldErrors()) {
String message = translate ? messageSource.getMessage(error, locale) : error.getCode();
View race.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Race</title>
<style type="text/css">
* {
margin: 0;
padding: 0;
}
View race.html
<div id="images">
<img id="image_lisa" width="32" height="32" src="lisa.png">
<img id="image_meggie" width="32" height="32" src="meggie.png">
</div>
<canvas id="canvas" width="854" height="480"></canvas>
<script type="text/javascript">
var Game = function() {
var canvas = document.getElementById('canvas');
this.ctx = canvas.getContext('2d');