Skip to content

Instantly share code, notes, and snippets.

@safx
safx / main.rs
Created October 26, 2023 12:19
Fine-grained reactive system: https://www.youtube.com/watch?v=GWB3vTWeLd4
use std::any::Any;
use std::cell::{Cell, RefCell};
use std::collections::{HashMap, HashSet};
use std::marker::PhantomData;
use web_sys::{console, window};
use wasm_bindgen::prelude::{Closure, JsCast};
#[derive(Default)]
struct Runtime {
signal_values: RefCell<Vec<Box<RefCell<dyn Any>>>>,
@safx
safx / App.tsx
Last active May 4, 2023 09:37
React Router Redirects (Auth) Example with React Context and TypeScript
import * as React from 'react';
import { BrowserRouter as Router, Link, Redirect, Route, RouteComponentProps, withRouter } from 'react-router-dom';
const UserAuthContext = React.createContext({
authenticated: false,
setAuthenticated: (_:boolean) => {}
});
const AuthExample = () => (
<Router>
@safx
safx / Lensy.swift
Created February 26, 2016 01:27
Lensy separates LensType into (non-failable) LensType and FailableLensType
//
// Lensy.swift
// Lensy
//
// Created by Safx Developer on 2016/02/12.
// Copyright © 2016 Safx Developers. All rights reserved.
//
// MARK: - Lenses protocols
@safx
safx / notify1
Created February 16, 2016 02:35
SSTP Notify
NOTIFY SSTP/1.1
Charset: UTF-8
Sender: Jenkins-Server
Event: OnBuildFailed
IfGhost: Jenkins,Hudson
Script: \0\v‥‥ビルドに失敗しました。\1なんとかしろ\e
@safx
safx / lazy.swift
Created October 20, 2015 11:51
lazy in Swift
class Foo {
static var x: Int = 0
lazy var a: Int! = { return x++ }()
}
class Bar {
static var y: Int = 0
lazy var b: Int? = { return y++ }()
}
@safx
safx / fuzzylife.cpp
Created May 2, 2015 14:45
Fuzzified Conway's game of life
#ifdef EMSCRIPTEN
#include <emscripten.h>
#endif
#include <SDL/SDL.h>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <time.h>
@safx
safx / bot.js
Created December 17, 2014 11:39
NuLabのTypetalk上でNTTドコモの雑談対話APIを利用するサンプルです (Google Apps Script)。 http://safx-dev.blogspot.jp/2014/12/typetalkwebhooknttapigoogle-apps-script.html
var dialogueUrl = 'https://api.apigw.smt.docomo.ne.jp/dialogue/v1/dialogue?APIKEY=zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz';
var typetalkUrl = 'https://typetalk.in/api/v1/topics/xxxx?typetalkToken=yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy';
var botName = 'foobar';
function doPost(e) {
var jsonString = e.postData.getDataAsString();
var post = JSON.parse(jsonString).post;
var user = '@' + post.account.name
var message = getMessage(post.message);
@safx
safx / sample.go
Created June 24, 2014 12:02
GoConvey Sample
package sample
import "errors"
func HexStringToInteger(s string) (int, error) {
num := 0
signum := 1
if signum == 0 {
return 0, nil
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.define :node1 do |m|
m.vm.box = "precise32"
m.vm.box_url = "http://files.vagrantup.com/precise32.box"
m.vm.network :private_network, ip: "192.168.1.11"
m.vm.network :forwarded_port, guest: 22, host: 22211, id: "ssh"
@safx
safx / playbook.xml
Last active August 29, 2015 13:56
install Oracle Java 7 SE SDK
- hosts: node1
user: vagrant
sudo: yes
tasks:
- name: install python-pycurl
apt: pkg=python-pycurl update_cache=yes
- name: Add the webupd8 APT repository
tags: java
apt_repository: repo="deb http://ppa.launchpad.net/webupd8team/java/ubuntu precise main" state=present