Skip to content

Instantly share code, notes, and snippets.

EDIT from 2019: Hi folks. I wrote this gist for myself and some friends, and it seems like it's gotten posted somewhere that's generated some (ahem, heated) discussion. The whitespace was correct when it was posted, and since then GitHub changed how it formats <pre> tags. Look at the raw text if you care about this. I'm sure someone could tell me how to fix it, but (thank you @anzdaddy for suggesting a formatting workaround) honestly this is a random throwaway gist from 2015, and someone more knowledgable about this comparison should just write a proper blog post about it. If you comment here I'll hopefully see it and stick a link to it up here. Cheers. @oconnor663

Here's the canonical TOML example from the TOML README, and a YAML version of the same. Which looks nicer?

title = "TOML Example"
 
@aristotle9
aristotle9 / Cargo.toml
Last active May 12, 2019 10:42
linked-list-rs
[package]
name = "linked-list"
version = "0.1.0"
authors = ["aristotle9 <lanfan.1987@gmail.com>"]
edition = "2018"
[dependencies]
@aristotle9
aristotle9 / find-rls-preview.sh
Last active August 18, 2020 08:11 — forked from MadratJerry/find-rls-preview.sh
Find the latest rust nightly version with rls-preview
#!/bin/bash
MAC=false
date -r "$now" +%Y-%m-%d &> /dev/null
if [ "$?" -ne "0" ]; then echo "LINUX"; MAC=false; else echo 'MAC'; MAC=true; fi
now=`date +%s`
while true
do
if [ "$MAC" == "true" ]; then data=`date -r "$now" +%Y-%m-%d`; else data=`date -d @"$now" +%Y-%m-%d`; fi
@aristotle9
aristotle9 / binary-search.rs
Last active January 28, 2019 14:15
binary search in ordered list, if not found, return the nearest **left** [(left + right)/2] index.(if need **right** index, use mid = [(left + right + 1) / 2])
const LIST: &[u32] = &[0, 10, 20, 30, 40, 50, 60, 70, 80, 90];
fn search(x: u32) -> usize {
let mut left: usize = 0;
let mut right: usize = LIST.len();
println!("\n\nstart search x({}) in {:?}", x, LIST);
let mut step: u32 = 0;
while true {
let mid = (left + right) / 2;
let val = LIST[mid];
Failed to parse method: QSizePolicy::QSizePolicy
entity: Entity { kind: Constructor, display_name: Some("QSizePolicy(QSizePolicy::Bits)"), location: Some(SourceLocation { file: Some(File { path: "/usr/local/Cellar/qt/5.9.1/include/QtWidgets/qsizepolicy.h" }), line: 178, column: 38, offset: 7665 }) }
error: Can't parse argument type: b: QSizePolicy::Bits
Failed to parse method: QSizePolicy::Bits::transposed
entity: Entity { kind: Method, display_name: Some("transposed()"), location: Some(SourceLocation { file: Some(File { path: "/usr/local/Cellar/qt/5.9.1/include/QtWidgets/qsizepolicy.h" }), line: 210, column: 14, offset: 8607 }) }
error: Can't parse return type: QSizePolicy::Bits: Type uses private class (QSizePolicy::Bits)
Failed to parse method: QTypeInfo::name
entity: Entity { kind: Method, display_name: Some("name()"), location: Some(SourceLocation { file: Some(File { path: "/usr/local/Cellar/qt/5.9.1/include/QtWidgets/qsizepolicy.h" }), line: 231, column: 1, offset: 9205 }) }
<?php
$a = [
2 => 1,
3 => 1,
4 => 1,
6 => 5,
7 => 5,
8 => 5,
9 => 7,
@aristotle9
aristotle9 / totp.clj
Created January 1, 2014 12:27
Clojure Server of Google Authenticator; Java version: https://github.com/wstrange/GoogleAuth
(ns xxx.totp
(:import org.apache.commons.codec.binary.Base32))
(def ^:const seed "QPA2GEXU3NNZUFKJL3NLZMC5YCA6UGSVDA3TFBJDXCZTQXYGYCYNKKWNU3IQG657CRWNUKNZGA3I2CLBUZYD3K55YZYQ====")
(def ^:const secret-size 10)
(def ^:const random-number-algorithm "SHA1PRNG")
(def ^:const window-size 3)
(defn new-secret
[]
@aristotle9
aristotle9 / Unpacker.java
Last active December 22, 2015 13:59
unpacker for MA pack file, and it's easy to generate pack file, possible to customize MA assets.
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
/**
* unpacker for MA pack file
*/
public final class Unpacker {
@aristotle9
aristotle9 / parse-sol.hs
Created July 18, 2012 08:12
Parse sol data
import qualified Data.ByteString as B
import Data.Binary.Strict.Get
import System.IO
import Text.Printf (printf)
import System.Environment (getArgs)
import Control.Applicative ((<$>))
import Data.Bits ((.|.), (.&.), shiftL, shiftR)
import Data.ByteString.UTF8 (toString)
import Text.JSON.Types
import Text.JSON (encode)
@aristotle9
aristotle9 / conc.hs
Created July 10, 2012 04:35
MVar in Haskell Concurrent
import Control.Concurrent
import Control.Concurrent.MVar
import Control.Monad.Fix (fix)
--seg:: MVar Int -> MVar Int -> Int -> IO ()
seg mself mnext n loop = do
mn <- takeMVar mself
putStrLn $ show mn
putMVar mnext n
loop