Skip to content

Instantly share code, notes, and snippets.

View marihachi's full-sized avatar
🕹️

marihachi marihachi

🕹️
View GitHub Profile
@marihachi
marihachi / test.ls
Last active August 29, 2015 14:24
LiveScriptのテスト
key = "name"
value = 100
obj =
"#key": value
obj2 = {+flagA, -FlagB}
url = @location
public partial class Form1 : Form
{
private Twitch.Twitter tw { set; get; }
private async void Form1_Load(object sender, EventArgs e)
{
// 今回はTwitterForAndroidのAPIキーを使用
tw = new Twitch.Twitter("3nVuSoBZnx6U4vzUxf5w", "Bcs59EFbbsdF6Sl9Ng71smgStWEGwXXKSjYvPVt7qys");
await tw.Authorize();
}

C#でHelloWolrd

Visual Studio For Windows Desktopでの作業を想定しています

メニューから ファイル->新しいプロジェクト で C#の、Windowsフォームアプリケーション を選んで何か名前を付けてOKをクリックします

プロジェクトが作成できたら、ツールボックスからButtonをフォーム上にドラッグしてきて、ボタンの配置をします。

次に、そのボタンをデザイナ上からダブルクリックすると、それのClickイベント(そのボタンがクリックされたときに呼び出されるメソッド)のブロックがコード上に生成されます。 そのブロックに以下のコードを追加してみましょう:

C#でテンプレート的な機能の実現

文字列中に乱数を挿入するなどテンプレート的な機能を実装したい場合がある。

これを実現するのは至って単純で、「<random>」などのトークンをC#のプレースホルダ(書式指定子)である「{0}」に置き換えれば良いというもの。

ただし、「{0}」の0はその置き換える値がString.Formatの第2引数以降の何番目かによって決定される。

以下のプログラムは、テンプレート文字列中のトークンの位置へ乱数(1~10)の挿入を行うものです:

var formatSource = "値は  です。";
@marihachi
marihachi / Switch.cs
Last active February 2, 2016 10:17
switch文のcase内での変数のスコープが気持ちが悪かったので、変わりとなるものを作ってみたけど使い方がスマートでないので結局使わなかった。なのでせめてここに残しておきます。
using System;
using System.Collections.Generic;
public class Switch<T>
{
public Switch(T target)
{
Target = target;
}
@marihachi
marihachi / Program.cs
Last active March 2, 2016 07:21
DxSharpのサンプルコード
using System;
using System.Drawing;
using System.Windows.Forms;
namespace DxSharp.Sample
{
public static class Program
{
public static void Main()
{

Required binary

  • ffmpeg
  • rtmpdump

Channel

超!A&G+

rtmpdump -r "rtmpe://fms1.uniqueradio.jp/" -a ?rtmp://fms-base2.mitene.ad.jp/agqr/ -y aandg22 -B %1 -v | ffmpeg -i pipe:0 %2

param

@marihachi
marihachi / ValidateableList.cs
Last active December 16, 2016 16:03
データの追加を検証可能なジェネリックリスト
using System;
using System.Collections;
using System.Collections.Generic;
namespace Utility
{
public class ValidateableList<T> : IList<T>
{
public ValidateableList(Func<T, bool> addValidater = null)
{
@marihachi
marihachi / updateTextFileSample.php
Last active December 26, 2016 12:53
テキストファイルの最初の行を削除して保存しなおすサンプル
<?php
$data = [];
// 読み込み
$handle = fopen("hoge.txt", "r");
if ($handle) {
while (($line = fgets($handle, 4096)) !== false) {
array_push($data, $line);
}
@marihachi
marihachi / get-session-test.js
Last active May 4, 2017 07:47
socket.io(サーバ側)からexpressのセッションを取得
const io = require('socket.io')(http);
const session = require('express-session');
const RedisStore = require('connect-redis')(session);
const cookie = require('cookie');
const cookieParser = require('cookie-parser');
const inspect = require('util').inspect;
const store = new RedisStore();
const sessionCookieName = 'sid';
const sessionSecret = 'hoge';