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 / gist:3366866
Created August 16, 2012 04:32
Power Line for Emacs
(defun dither-xpm (color1 color2)
"Return an XPM dither string representing."
(format "/* XPM */
static char * dither[] = {
\"12 18 2 1\",
\". c %s\",
\" c %s\",
\"....... . . \",
\".. . . . \",
\"..... . . . \",
@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 / bowling.hs
Last active December 26, 2015 13:19
ボウリングのスコアを計算するスクリプト
score' :: Int -> Char -> Int
score' _ '-' = 0
score' b '/' = 10 - b
score' _ 'X' = 10
score' _ '1' = 1
score' _ '2' = 2
score' _ '3' = 3
score' _ '4' = 4
score' _ '5' = 5
score' _ '6' = 6
@safx
safx / bowling.ls
Created October 23, 2013 16:08
ボウリングのスコアを計算するスクリプト
#_ = require \prelude-ls
class Frame
(pin, prev)->
@cell = pin
@prev = prev
@next = null
prev.next = this if prev?
#frameScore: -> _.fold (+), 0, @cell
@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);