Skip to content

Instantly share code, notes, and snippets.

const csvStringToArray = strData =>
{
const objPattern = new RegExp(("(\\,|\\r?\\n|\\r|^)(?:\"([^\"]*(?:\"\"[^\"]*)*)\"|([^\\,\\r\\n]*))"),"gi");
let arrMatches = null, arrData = [[]];
while (arrMatches = objPattern.exec(strData)){
if (arrMatches[1].length && arrMatches[1] !== ",")arrData.push([]);
arrData[arrData.length - 1].push(arrMatches[2] ?
arrMatches[2].replace(new RegExp( "\"\"", "g" ), "\"") :
arrMatches[3]);
}
@chenshuo
chenshuo / multiarray.cc
Last active October 16, 2023 14:29
MultiArray
#include <assert.h>
#include <array>
#include <functional>
#include <numeric>
template<typename T, int N>
class MultiArrayBase
{
public:
MultiArrayBase(T* data, const std::array<int, N>& dim)
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#
# Copyright © 2018 beebird
#
# Distributed under terms of the MIT license.
"""
@barbolo
barbolo / benchamark_hash_to_json.rb
Last active September 24, 2022 03:32
Benchmark of JSON rendering in Ruby
# gem install multi_json json yajl-ruby oj benchmark-memory
require 'multi_json'
require 'json'
require 'yajl'
require 'oj'
require 'benchmark'
require 'benchmark-memory'
hash1 = {
@bgadrian
bgadrian / set.go
Last active May 28, 2025 02:02
How to implement a simple set data structure in golang
type Set struct {
list map[int]struct{} //empty structs occupy 0 memory
}
func (s *Set) Has(v int) bool {
_, ok := s.list[v]
return ok
}
@kentquirk
kentquirk / test.js
Created June 28, 2018 03:40
Using Go structs from JS
m = require("./objtest2.js");
h = m.hashobj({
name: "Kent",
address: "Somewhere in Space and Time",
city: "Specificity",
state: "CT"
})
console.log(h.hash.slice(0, 4))

Hello World In Python 10 Ways

1. general

print('Hello World')

2. sys stdout

import sys
@a2ikm
a2ikm / patch_migrate.ruby
Last active April 23, 2019 02:49
rake db:migrateでdevelopmentだけでなくtestもまとめてマイグレーション走らせるやつ for Rails 5.1
module ActiveRecord::Tasks::DatabaseTasks
class <<self
prepend Module.new {
def migrate(environment = env)
each_current_configuration(environment) { |configuration|
begin
ActiveRecord::Base.establish_connection(configuration)
super()
ensure
ActiveRecord::Base.establish_connection(environment.to_sym)
@dublado
dublado / gist:cf8c4fbe359c686266eb7723a0a08c55
Created March 6, 2018 14:58
Apache Bench (ab) to POST JSON to an API
$ cat test.json
json='{ "timestamp" : 1484825894873, "test" : "test"}'
ab -c 10 -n 1000 -p test.json -T application/x-www-form-urlencoded https://example.com/test
#https://prabuddha.me/apache-bench-ab-post-json-api/
@mashariqk
mashariqk / postmanHelper.js
Created February 26, 2018 19:14
This function will replace all environmental variables in the request with their values.
function returnParsedUrl() {
var url = request.url.trim();
var firstArray = url.split('{{');
var listOfProperties = [""];
for (i = 1; i < firstArray.length; i++) {
listOfProperties[i - 1] = firstArray[i].substring(0, firstArray[i].indexOf("}}"));
}
var completeUrl = "";
for (i = 0; i < firstArray.length; i++) {
if (firstArray[i].includes("}}")) {