Last active
August 4, 2022 02:14
-
-
Save fdncred/6f5fb149c014c6de039401a6a07d3046 to your computer and use it in GitHub Desktop.
Revisions
-
fdncred revised this gist
Aug 4, 2022 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -65,7 +65,7 @@ Commands specifically made for finding and manipulating binary data. Since namin - [x] `bits rol` aka `rotate --left` - bitwise shift left move a bit left and adds it to the right - [x] `bits ror` aka `rotate --right` - bitwise shift right move a bit right and adds it to the left - [x] `bits and` aka `&` -
fdncred revised this gist
Aug 4, 2022 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -62,7 +62,7 @@ Commands specifically made for finding and manipulating binary data. Since namin - [x] `bits shr` aka `shift --right` aka `>>` -bitwise shift right moves bits right - [x] `bits rol` aka `rotate --left` - bitwise shift left move a bit left and adds it to the right - [ ] `bits ror` aka `rotate --right` -
fdncred revised this gist
Aug 1, 2022 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -59,7 +59,7 @@ Commands specifically made for finding and manipulating binary data. Since namin - [x] `bits shl` aka `shift --left` aka `<<` -bitwise shift left moves bits left - [x] `bits shr` aka `shift --right` aka `>>` -bitwise shift right moves bits right - [ ] `bits rol` aka `rotate --left` -
fdncred revised this gist
Aug 1, 2022 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -56,7 +56,7 @@ Commands specifically made for finding and manipulating binary data. Since namin * https://github.com/niconii/twiddle * https://github.com/gnzlbg/bitwise - [x] `bits shl` aka `shift --left` aka `<<` -bitwise shift left moves bits left - [ ] `bits shr` aka `shift --right` aka `>>` -
fdncred revised this gist
Jul 30, 2022 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -74,7 +74,7 @@ Commands specifically made for finding and manipulating binary data. Since namin - [x] `bits or` aka `|` - bitwise or performs logical or operation on each pair of bits - [x] `bits xor` aka `^` - bitwise xor perofrms logical exclusive or operation on each pair of bits - [x] `bits not` aka `~` aka `complement` -
fdncred revised this gist
Jul 30, 2022 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -71,7 +71,7 @@ Commands specifically made for finding and manipulating binary data. Since namin - [x] `bits and` aka `&` - bitwise and performas logical and operation on each pair of bits - [x] `bits or` aka `|` - bitwise or performs logical or operation on each pair of bits - [ ] `bits xor` aka `^` -
fdncred revised this gist
Jul 30, 2022 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -68,7 +68,7 @@ Commands specifically made for finding and manipulating binary data. Since namin - [ ] `bits ror` aka `rotate --right` - bitwise shift right move a bit right and adds it to the left - [x] `bits and` aka `&` - bitwise and performas logical and operation on each pair of bits - [ ] `bits or` aka `|` -
fdncred revised this gist
Jul 30, 2022 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -77,7 +77,7 @@ Commands specifically made for finding and manipulating binary data. Since namin - [ ] `bits xor` aka `^` - bitwise xor perofrms logical exclusive or operation on each pair of bits - [x] `bits not` aka `~` aka `complement` - performs logical negation on each bit TBD - we could add later or make params or leave out and there are many more we could add -
fdncred revised this gist
Jul 11, 2022 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -33,7 +33,7 @@ Commands specifically made for finding and manipulating binary data. Since namin - [x] `bytes ends-with` - returns bool of whether a buffer ends with specified byte(s) - [x] `bytes find-replace` aka `bytes replace` - find and replace specified bytes - [x] `bytes add` -
fdncred revised this gist
Jul 11, 2022 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -39,7 +39,7 @@ Commands specifically made for finding and manipulating binary data. Since namin - [x] `bytes add` - add specified bytes to the --start, --end, --index - [x] `bytes remove` - remove specified bytes from --start, --end, --index - [x] `bytes reverse` -
fdncred revised this gist
Jul 11, 2022 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -27,7 +27,7 @@ Commands specifically made for finding and manipulating binary data. Since namin - [x] `bytes size` aka `bytes length` - return the size of something in bytes - [x] `bytes collect` - collect bytes like str collect - [x] `bytes ends-with` -
fdncred revised this gist
Jul 11, 2022 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -21,7 +21,7 @@ Commands specifically made for finding and manipulating binary data. Since namin - [x] `bytes to-str` - point to `decode utf-8` - returns specified bytes as a utf-8 string - [x] `bytes build` - kind of like buildstring but for bytes - [x] `bytes size` aka `bytes length` -
fdncred revised this gist
Jul 9, 2022 . 1 changed file with 21 additions and 21 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -8,44 +8,44 @@ Commands specifically made for finding and manipulating binary data. Since namin * https://github.com/Mackirac/binary_byte * https://github.com/gmantaos/file-utils - [x] `bytes` query the bytes of a buffer - [x] `bytes at` maybe thought of like `str sub-string`? - returns the byte at a specified offset in decimal 10 or hex 0x10 - returns the bytes in a range if specified like 1..10 - [x] `bytes index-of` aka `bytes contains` - finds the index of a specified hex byte 0x10 - finds the index of a specified byte buffer - [x] `bytes to-str` - point to `decode utf-8` - returns specified bytes as a utf-8 string - [ ] `bytes build` - kind of like buildstring but for bytes - [x] `bytes size` aka `bytes length` - return the size of something in bytes - [ ] `bytes collect` - collect bytes like str collect - [x] `bytes ends-with` - returns bool of whether a buffer ends with specified byte(s) - [ ] `bytes find-replace` aka `bytes replace` - find and replace specified bytes - [x] `bytes add` - add specified bytes to the --start, --end, --index - [ ] `bytes remove` - remove specified bytes from --start, --end, --index - [x] `bytes reverse` - reverse a buffer of bytes - [x] `bytes starts-with` - returns bool of whether a buffer starts with specified byte(s) # the `bits` command @@ -56,28 +56,28 @@ Commands specifically made for finding and manipulating binary data. Since namin * https://github.com/niconii/twiddle * https://github.com/gnzlbg/bitwise - [ ] `bits shl` aka `shift --left` aka `<<` -bitwise shift left moves bits left - [ ] `bits shr` aka `shift --right` aka `>>` -bitwise shift right moves bits right - [ ] `bits rol` aka `rotate --left` - bitwise shift left move a bit left and adds it to the right - [ ] `bits ror` aka `rotate --right` - bitwise shift right move a bit right and adds it to the left - [ ] `bits and` aka `&` - bitwise and performas logical and operation on each pair of bits - [ ] `bits or` aka `|` - bitwise or performs logical or operation on each pair of bits - [ ] `bits xor` aka `^` - bitwise xor perofrms logical exclusive or operation on each pair of bits - [ ] `bits not` aka `~` aka `complement` - performs logical negation on each bit TBD - we could add later or make params or leave out and there are many more we could add -
fdncred revised this gist
Jul 9, 2022 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -33,7 +33,7 @@ Commands specifically made for finding and manipulating binary data. Since namin `bytes ends-with` - returns bool of whether a buffer ends with specified byte(s) `bytes find-replace` aka `bytes replace` - find and replace specified bytes `bytes add` -
fdncred revised this gist
Mar 18, 2022 . 1 changed file with 0 additions and 177 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,177 +0,0 @@ -
fdncred revised this gist
Mar 18, 2022 . 1 changed file with 177 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1 +1,177 @@ # Pattern Matching Some prior-art inspiration for an upcoming `match` command in nushell. ## Scala ```Scala import scala.util.Random val x: Int = Random.nextInt(10) x match { case 0 => "zero" case 1 => "one" case 2 => "two" case _ => "other" } ``` ## Julia ```julia using Match @match item begin pattern1 => result1 pattern2, if cond end => result2 pattern3 || pattern4 => result3 _ => default_result end ``` ## ClojureScript ```clojure (ns foo.bar (:require [cljs.core.match :refer-macros [match]])) (doseq [n (range 1 101)] (println (match [(mod n 3) (mod n 5)] [0 0] "FizzBuzz" [0 _] "Fizz" [_ 0] "Buzz" :else n))) ``` ## Elixir ```elixir iex> {a, b, c} = {:hello, "world", 42} {:hello, "world", 42} iex> a :hello iex> b "world" ``` ## Haskell ```haskell bmiTell :: (RealFloat a) => a -> String bmiTell bmi | bmi <= 18.5 = "You're underweight, you emo, you!" | bmi <= 25.0 = "You're supposedly normal. Pffft, I bet you're ugly!" | bmi <= 30.0 = "You're fat! Lose some weight, fatty!" | otherwise = "You're a whale, congratulations!" ``` ## Python ```python parser = argparse.ArgumentParser() parser.add_argument('command', choices=['push', 'pull', 'commit']) args = parser.parse_args() match args.command: case 'push': print('pushing') case 'pull': print('pulling') case _: parser.error(f'{args.command!r} not yet implemented') ``` ## Elm ```elm toName : User -> String toName user = case user of Regular name age -> name Visitor name -> name -- toName (Regular "Thomas" 44) == "Thomas" -- toName (Visitor "kate95") == "kate95" ``` ## F# ```fsharp type Color = | Red = 0 | Green = 1 | Blue = 2 let printColorName (color:Color) = match color with | Color.Red -> printfn "Red" | Color.Green -> printfn "Green" | Color.Blue -> printfn "Blue" | _ -> () printColorName Color.Red printColorName Color.Green printColorName Color.Blue ``` ## Erlang ```erlang > N = {12, banana}. {12,banana} > {A, B} = N. {12,banana} > A. 12 > B. banana ``` ## C# ```csharp string WaterState(int tempInFahrenheit) => tempInFahrenheit switch { (> 32) and (< 212) => "liquid", < 32 => "solid", > 212 => "gas", 32 => "solid/liquid transition", 212 => "liquid / gas transition", }; ``` ## ReasonML ```reasonml switch (x) { | true => f("t") | false => g("f") }; switch (x) { | "a" => 4.0 | "tree" => 1.23 | _ => 77.5 }; ``` ## Swift ```swift let point = (1, 2) switch point { case (0, 0): print("(0, 0) is at the origin.") case (-2...2, -2...2): print("(\(point.0), \(point.1)) is near the origin.") default: print("The point is at (\(point.0), \(point.1)).") } // Prints "(1, 2) is near the origin." ``` -
fdncred revised this gist
Mar 18, 2022 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1 @@ -
fdncred revised this gist
Feb 14, 2022 . 1 changed file with 9 additions and 8 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,7 +2,7 @@ Commands specifically made for finding and manipulating binary data. Since naming is hard, we may end up changing the name. :) # the `bytes` command ### potential crates for bytes * https://docs.rs/bytes/latest/bytes/ * https://github.com/cronosun/abin/ * https://github.com/Mackirac/binary_byte @@ -50,7 +50,7 @@ Commands specifically made for finding and manipulating binary data. Since namin # the `bits` command ### protentional crates for bits * https://github.com/kkayal/bitlab * https://github.com/RustyNixieTube/bit_op * https://github.com/niconii/twiddle @@ -81,10 +81,11 @@ Commands specifically made for finding and manipulating binary data. Since namin - performs logical negation on each bit TBD - we could add later or make params or leave out and there are many more we could add * `sal` - shift arithmatic left * `sar` - shift arithmatic right * `rcl` - rotate carry left * `rcr` - rotate carry right * `shld` - shift left number of bits * `shrd` - shift right number of bits -
fdncred revised this gist
Feb 11, 2022 . 1 changed file with 9 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -79,3 +79,12 @@ Commands specifically made for finding and manipulating binary data. Since namin `bits not` aka `~` aka `complement` - performs logical negation on each bit TBD - we could add later or make params or leave out and there are many more we could add `sal` - shift arithmatic left `sar` - shift arithmatic right `rcl` - rotate carry left `rcr` - rotate carry right `shld` - shift left number of bits `shrd` - shift right number of bits -
fdncred revised this gist
Feb 11, 2022 . 1 changed file with 4 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -56,16 +56,16 @@ Commands specifically made for finding and manipulating binary data. Since namin * https://github.com/niconii/twiddle * https://github.com/gnzlbg/bitwise `bits shl` aka `shift --left` aka `<<` -bitwise shift left moves bits left `bits shr` aka `shift --right` aka `>>` -bitwise shift right moves bits right `bits rol` aka `rotate --left` - bitwise shift left move a bit left and adds it to the right `bits ror` aka `rotate --right` - bitwise shift right move a bit right and adds it to the left `bits and` aka `&` -
fdncred revised this gist
Feb 10, 2022 . 1 changed file with 81 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1 +1,81 @@ # Introducing the `bytes` and the `bits` command. Commands specifically made for finding and manipulating binary data. Since naming is hard, we may end up changing the name. :) # the `bytes` command ### crates for bytes * https://docs.rs/bytes/latest/bytes/ * https://github.com/cronosun/abin/ * https://github.com/Mackirac/binary_byte * https://github.com/gmantaos/file-utils `bytes` query the bytes of a buffer `bytes at` maybe thought of like `str sub-string`? - returns the byte at a specified offset in decimal 10 or hex 0x10 - returns the bytes in a range if specified like 1..10 `bytes index-of` aka `bytes contains` - finds the index of a specified hex byte 0x10 - finds the index of a specified byte buffer `bytes to-str` - point to `decode utf-8` - returns specified bytes as a utf-8 string `bytes build` - kind of like buildstring but for bytes `bytes size` aka `bytes length` - return the size of something in bytes `bytes collect` - collect bytes like str collect `bytes ends-with` - returns bool of whether a buffer ends with specified byte(s) `bytes find-replace` - find and replace specified bytes `bytes add` - add specified bytes to the --start, --end, --index `bytes remove` - remove specified bytes from --start, --end, --index `bytes reverse` - reverse a buffer of bytes `bytes starts-with` - returns bool of whether a buffer starts with specified byte(s) # the `bits` command ### crates for bits * https://github.com/kkayal/bitlab * https://github.com/RustyNixieTube/bit_op * https://github.com/niconii/twiddle * https://github.com/gnzlbg/bitwise `bits shift --left` aka `<<` -bitwise shift left moves bits left `bits shift --right` aka `>>` -bitwise shift right moves bits right `bits rotate --left` - bitwise shift left move a bit left and adds it to the right `bits rotate --right` - bitwise shift right move a bit right and adds it to the left `bits and` aka `&` - bitwise and performas logical and operation on each pair of bits `bits or` aka `|` - bitwise or performs logical or operation on each pair of bits `bits xor` aka `^` - bitwise xor perofrms logical exclusive or operation on each pair of bits `bits not` aka `~` aka `complement` - performs logical negation on each bit -
fdncred created this gist
Feb 10, 2022 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1 @@