Skip to content

Instantly share code, notes, and snippets.

@cyrusn
cyrusn / rps3.js
Last active August 29, 2015 13:56
to find the expected value of the number of game played in 3 player games to find the winner. ans 9/4
var n = 100000;
var result =0; // no of sub-game played
var record = 0;
function play(){
for (i=0;i<n;i++){
play3();
record = record + result;
result = 0;
}
@cyrusn
cyrusn / install.sh
Last active November 4, 2015 09:18
Terminal setting on OSX
#!/bin/bash
# set Autocomplete on
# use zsh auto completion instead
# echo "set completion-ignore-case On" >> ~/.inputrc
# install xcode command tool
## install
xcode-select --install
## check
@cyrusn
cyrusn / oNetResult.go
Last active July 26, 2016 01:08
search the Interest Code for given job_ID through O'net online website "http://www.onetonline.org/"
package main
import (
"fmt"
"strings"
"sync"
"github.com/PuerkitoBio/goquery"
)
@cyrusn
cyrusn / auth.go
Last active December 23, 2016 17:41
handler wraper for authentication in golang
/*
package auth is a handler wrapper for authentication
*/
package auth
import (
"encoding/base64"
"encoding/json"
"net/http"
"strings"
@cyrusn
cyrusn / jsonAPI.go
Created December 23, 2016 04:09
Wirte JSON and Error message for net/http ResponseWriter
package jsonAPI
import (
"encoding/json"
"fmt"
"net/http"
)
type MessageResponse struct {
Message string `json:"message"`
var form = FormApp.openByUrl("paste_the_link_of_the_form_here")
var students = [{"classcode":"1A","classno":1,"name":"Apple"},
{"classcode":"1A","classno":2,"name":"Ball"},
{"classcode":"1A","classno":3,"name":"Cat"},
{"classcode":"1A","classno":4,"name":"Dog"},
{"classcode":"1A","classno":5,"name":"Egg"},
{"classcode":"1A","classno":6,"name":"Fan"},
{"classcode":"1A","classno":7,"name":"Goat"},
{"classcode":"1A","classno":8,"name":"Hand"},
{"classcode":"1A","classno":9,"name":"Indian"},
@cyrusn
cyrusn / main.py
Created April 13, 2018 08:07
Control IR cut for IR cut camera
# https://www.waveshare.com/rpi-ir-cut-camera.htm
import RPi.GPIO as GPIO
from time import sleep
GPIO.setmode(GPIO.BOARD)
GPIO.setwarnings(False)
LDR_PIN = 11
POWER_SUPPLY = 13
#!/usr/bin/python3
# -*- coding: utf-8 -*-
"""
ZetCode PyQt5 tutorial
This is a Tetris game clone.
Author: Jan Bodnar
Website: zetcode.com
@cyrusn
cyrusn / mdinline2reference.py
Created June 4, 2018 12:23
[markdown] convert reference link to inline link vice versa
import sys
import re
from math import log, floor
query = sys.argv[1]
# query = """
# - [Riverbank | Software | PyQt | What is PyQt?](https://riverbankcomputing.com/software/pyqt/intro)
# - [![image](https://www.riverbankcomputing.com/@@/resources/logo.png)](https://riverbankcomputing.com/software/pyqt/intro)
# """
@cyrusn
cyrusn / ConvertPages2PDF.scpt
Last active June 30, 2018 00:53
Apple JXA automate to convert pages file to pdf.
var app = Application.currentApplication()
app.includeStandardAdditions = true
files = app.chooseFile({
withPrompt: 'Pick the files to process:',
multipleSelectionsAllowed: true
})
delay(0.5)