M

@mmarchese

relabeler

Lua
2 years ago
local serialPattern = '^S%d%d%d%d%d%d%d%d$' -- something ending in 8 numbers local FAIL_OUTPUT = 1 -- This is called by the Keyence barcode reader each time it's triggered. function readformatEvent() local barcodes = getBarcodesFromReader() if #barcodes == 0 then setReaderFailOutput() return 'ERROR: No barcodes found' end

double.TryParse

C#
3 years ago
using System; namespace MyCompiler { class Program { public static void Main(string[] args) { double a; bool r; // r = double.TryParse(" 1.2 ", out a); // True, 1.2 // r = double.TryParse(" -1.2 ", out a); // True, -1.2 // r = double.TryParse("+1.2", out a); // True, 1.2

Convert.ToDouble

C#
3 years ago
using System; namespace MyCompiler { class Program { public static void Main(string[] args) { double a = null; // a = Convert.ToDouble(" 1.2 "); // a = Convert.ToDouble(" -1.2 "); // a = Convert.ToDouble("+1.2"); // a = Convert.ToDouble(null); // 0

python str.isdigit()

Python
3 years ago
print('123'.isdigit()) print('-123'.isdigit()) print('123.0'.isdigit()) print('D2-H-NON'.isdigit())

python dict.update(other_dict) works like HTTP PUT

Python
3 years ago
dest = {'a': 1} src = {'a': 2, 'b': 2} dest.update(src) for k in dest: print(f'{k}: {dest[k]}')

python dict.copy() is shallow

Python
3 years ago
# a = {'a': 'asdf'} # b = a.copy() # b['a'] = 'yo' # print(a['a']) # print(b['a']) a = {'a': {'a': 'asdf'}} b = a.copy() b['a']['a'] = 'yo' print(a['a']['a'])

C++ trying std::array

C++
4 years ago
#include <iostream> #include <array> void foo(constexpr int size) { std::array<int, size> foo = { 0 }; foo.fill(5) std::cout << foo[2] << foo.size; } int main() {

C++ trying out refs

C++
4 years ago
#include <iostream> int& square(int& x) { x = x * x; return x; } int square2(int& x) { return x * x; }

C++ when new is needed

C++
4 years ago
#include <iostream> void foo(int s) { int arr[s] = { 0 }; arr[2] = 5; std::cout << arr[3] << " " << arr[2]; } // int* foo2(int s) { // int arr[s] = { 0 };

hello

C++
4 years ago
#include <iostream> #include <cstring> int main() { // std::cout << true << std::endl; // 0 // std::cout << false << std::endl; // 1 // std::cout << std::boolalpha; // std::cout << true << std::endl; // true // std::cout << false << std::endl; // false