Skip to content

Instantly share code, notes, and snippets.

@yamakk
yamakk / App.swift
Last active August 12, 2022 17:30
Simplest MVVM with Combine
import Foundation
import SwiftUI
import Combine
struct API {
//private let url = URL(string: "https://hacker-news.firebaseio.com/v0/newstories.json")!
private let url = URL(string: "https://hacker-news.firebaseio.com/wrongendpoint")!
enum Error: LocalizedError, Identifiable {
var id: String { localizedDescription }
case addressUnreachable(URL)
@yamakk
yamakk / anki_shuffle_selection_template.html
Last active December 8, 2021 06:44
An anki template for shuffled choices - 文法の4択問題などは選択肢の並び順で正解を記憶してしまうことがあるため毎回選択肢をシャッフルできるAnkiテンプレート
<div class="ankiCard">
<div id="front-text" style="padding:15px; text-align:left;">{{Front}}</div>
<div id="hide" style="display:none;">
<div id="choices">{{choices}}</div>
</div>
<div id="selections" style="text-align:left; margin-left:10px;">
</div>
</div>
<script>
@yamakk
yamakk / nx2gt.py
Created March 25, 2021 23:32 — forked from bbengfort/nx2gt.py
Convert a networkx to graph-tool graph
import networkx as nx
import graph_tool as gt
def get_prop_type(value, key=None):
"""
Performs typing and value conversion for the graph_tool PropertyMap class.
If a key is provided, it also ensures the key is in a format that can be
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@yamakk
yamakk / 0_reuse_code.js
Created February 15, 2017 12:40
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@yamakk
yamakk / mygoogledocs.py
Created December 18, 2011 23:07
googledocsをcsvにエクスポート
#coding:utf-8
import gdata.docs.data
import gdata.docs.client
import gdata.docs.service
import gdata.spreadsheet.service
"""
SpreadSheetは
GoogleDocsからドキュメントをローカルにエクスポートするクラス
アカウント情報とdocumentのid, そしてexportしたいファイルの名前が必要
@yamakk
yamakk / mymecab.scala
Created December 6, 2011 11:56
mymecab.scala
import java.text.Normalizer
import scala.collection.mutable.ArrayBuffer
import org.chasen.mecab.{MeCab, Tagger, Node}
/*
scalac mymecab.scala
scala MyMeCabTest
ArrayBuffer(サイト, リンクフリー, リンクフリー)
@yamakk
yamakk / ignoredecodetest.scala
Created December 6, 2011 08:49
ignoredecodetest.scala utf-8でdecodeできないファイルをscalaで扱う
import java.io.{InputStreamReader, FileInputStream, BufferedReader}
import java.nio.charset.{Charset, CharsetDecoder, CodingErrorAction}
/*
通常 Source.fromFile("sample.txt")では
java.nio.charset.MalformedInputException: Input length = 1
エラーが出る場合使う.
*/
object IgnoreDecodeTest{
@yamakk
yamakk / mecab-java-0.98.Makefile
Created December 5, 2011 13:51
mecab-java-0.98 Makefile for MacOS10.6.8
JAVA_BASE=/System/Library/Frameworks/JavaVM.framework/Versions/1.6
JAVA_HOME=$(JAVA_BASE)/Home
TARGET=MeCab
JAVAC=$(JAVA_HOME)/bin/javac -encoding utf-8
JAVA=$(JAVA_HOME)/bin/java -Dfile.encoding=utf-8
JAR=$(JAVA_HOME)/bin/jar
CXX=g++
INCLUDE=/System/Library/Frameworks/JavaVM.framework/Versions/A/Headers
PACKAGE=org/chasen/mecab
@yamakk
yamakk / multiprocess_mongo.py
Created December 4, 2011 12:47
multiprocessing to mongodb single processと4processの比較
#coding:utf-8
import os
import time
from multiprocessing import Process
import pymongo
def print_tweet(collection):
db = pymongo.Connection().twitter
pid = os.getpid()