Skip to content

Instantly share code, notes, and snippets.

@cdrubin
cdrubin / code.php
Last active April 23, 2020 14:33
shared
function count_instances_of_word_in_string( $word, $string ) {
$found = 0;
$matches = preg_match( $word, $string );
return count( $matches );
}
$paragraph = <<<EOP
This is some text and I expect there will be some
some words that appear more than once. Especially if
Alt Bar Fri Hun Patrons Price Rain Res Type Est WillWait
X1 T F F T Some $$$ F T French 0-10 T
X2 T F F T Full $ F F Thai 30-60 F
X3 F T F F Some $ F F Burger 0-10 T
X4 T F T T Full $ F F Thai 10-30 T
X5 T F T F Full $$$ F T French >60 F
X6 F T F T Some $$ F T Italian 0-10 T
X7 F T F F None $ T F Burger 0-10 F
X8 F F F T Some $$ T T Thai 0-10 T
X9 F T T F Full $ T F Burger >60 F
@cdrubin
cdrubin / BenchmarkMongo.php
Last active October 2, 2015 14:30
Benchmark Mongo
<?php
// depends on:
//
// benchmarkeducation/matchmaker
// xmarcos/dot-container
// from composer
// for convenient use of same connection to return collections
@cdrubin
cdrubin / mongoose.js
Created March 4, 2011 01:36
no error bubbling up when saving to a non-existant property
(function() {
var Schema, User, UserSchema, app, db, express, mongoose, util;
util = require('util');
express = require('express');
mongoose = require('mongoose');
app = express.createServer();
db = mongoose.connect('XXX');
Schema = mongoose.Schema;
UserSchema = new Schema({
firstname: String,
use curl
import curl/Curl
import io/FileWriter, structs/ArrayList
main: func (args: ArrayList<String>) {
if(args length() <= 1) {
printf("Usage: %s URL\n", args[0])
exit(0)
}
// in the C header :
struct Skt_str {
int skt; /* skt handle */
SKTEVENT port; /* associated port */
int type; /* PM_SERVER, PM_CLIENT, PM_ACCEPT */
char *sktname; /* name of socket */
char *hostname; /* name of host */
};
import net/ServerSocket
main: func {
socket := ServerSocket new()
socket bind(2800). listen(10)
while(true) {
conn := socket accept()
"Got new client!" println()
import net/ServerSocket
main: func {
socket := ServerSocket new()
socket bind(2800). listen(10)
while(true) {
conn := socket accept()
"Got new client!" println()