Skip to content

Instantly share code, notes, and snippets.

View Moligaloo's full-sized avatar

Moligaloo Moligaloo

  • ByteDance
  • Shanghai, China
View GitHub Profile
@Moligaloo
Moligaloo / post-json.rb
Created April 10, 2022 19:34
Post HTTP JSON data using Ruby builtin HTTP library
# copied from https://stackoverflow.com/questions/2024805/ruby-send-json-request
require 'net/http' #net/https does not have to be required anymore
require 'json'
require 'uri'
uri = URI('https://your.secure-url.com')
Net::HTTP.start(uri.host, uri.port, :use_ssl => uri.scheme == 'https') do |http|
request = Net::HTTP::Post.new(uri, 'Content-Type' => 'application/json')
request.body = {parameter: 'value'}.to_json
@Moligaloo
Moligaloo / viterbi.io
Created December 10, 2021 08:06
Viterbi algorithm written in IoLanguage
obs := list("normal", "cold", "dizzy")
states := list("Healthy", "Fever")
start_p := Map with(
"Healthy", 0.6,
"Fever", 0.4
)
trans_p := Map with(
"Healthy", Map with(
"Healthy", 0.7,
"Fever", 0.3
@Moligaloo
Moligaloo / viterbi.moon
Created December 9, 2021 10:05
Viterbi algorithm written in MoonScript
obs = {'normal', 'cold', 'dizzy'}
states = {'Healthy', 'Fever'}
start_p = {
Healthy: 0.6,
Fever: 0.4
}
trans_p = {
Healthy: {
Healthy: 0.7,
@Moligaloo
Moligaloo / viterbi.js
Last active December 10, 2021 06:58
Viterbi algorithm example
const obs = ["normal", "cold", "dizzy"]
const states = ["Healthy", "Fever"]
const start_p = {
Healthy: 0.6,
Fever: 0.4,
}
const trans_p = {
Healthy: {
Healthy: 0.7,
@Moligaloo
Moligaloo / Main.hx
Created January 25, 2021 12:50
Find square root by dichotomy and newton iteration
class Main {
public static function main() {
trace(dichotomySqrt(2));
trace(newtonSqrt(2));
}
static function dichotomySqrt(x:Float):Float {
if (x < 0) {
return Math.NaN;
}
@Moligaloo
Moligaloo / AlwaysAllowSimulatorAccessNetwork.sh
Created April 27, 2020 09:21
always allow simulator process to access network, avoid annoying network permission request
#!/bin/bash
# Script to disable the iOS Simulator app from showing the "Do you want the application xxxx to accept incoming network connections?" pop-up every time the app is run
echo "> Enter password to temporarily shut firewall off"
sudo /usr/libexec/ApplicationFirewall/socketfilterfw --setglobalstate off
echo "> Add Xcode as a firewall exception"
/usr/libexec/ApplicationFirewall/socketfilterfw --add /Applications/Xcode.app/Contents/MacOS/Xcode
@Moligaloo
Moligaloo / Block+asJson.io
Created May 22, 2018 15:37
Compile block to AST using JSON format
#!/usr/bin/env io
Yajl
Regex
Message do(
asMap := method(
if(
self name allMatchesOfRegex("(^[0-9\"])|true|false|nil") isNotEmpty,
@Moligaloo
Moligaloo / CFunction.io
Last active May 7, 2018 03:35
Directly parse C function declaration
#!/usr/bin/env io
CFunction := Object clone do(
returnType ::= nil
name ::= nil
paramTypes ::= nil
curlyBrackets := method(
msg_list := list()
msg := call argAt(0)
@Moligaloo
Moligaloo / MemberListFromCStruct.io
Created May 5, 2018 08:57
get member list from struct definition using C style DSL
#!/usr/bin/env io
StructDefinition := Object clone do(
name ::= ""
memberList ::= list()
with := method(name,
self clone setName(name) setMemberList(list())
)
@Moligaloo
Moligaloo / combine-video-clips.m
Last active May 11, 2016 09:31
Combine video clips in iOS using AVFoundation
-(void) composeVideoClips:(NSMutableArray<AVURLAsset *> *)videoClips
forComposition:(AVMutableComposition *)composition
mediaType:(NSString *)mediaType
{
AVMutableCompositionTrack * composedTrack =
[composition addMutableTrackWithMediaType:mediaType
preferredTrackID:kCMPersistentTrackID_Invalid];
CMTime time = kCMTimeZero;
for (AVURLAsset *videoClip in videoClips) {