Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

{
"name": "United States of America",
"population": 313900000,
"capital": "Washington D.C.",
"major_cities": ["New York", "Los Angeles", "Chicago", "Miami", "Boston"]
}
@toinetoine
toinetoine / with.cs
Last active August 29, 2015 14:08
Printing cell A1 from an excel sheet named 'Sheet1' of the workbook 'ExcelWorkbook.xlsx' using Koogra in .NET
/*
* Must have refrences the dlls:
* Net.SourceForge.Koogra.dll (here: http://www.antoinedahan.com/blog/ReadingExcelFilesWithKoogra/Net.SourceForge.Koogra.dll)
* Ionic.Utils.Zip.dll (here: http://www.antoinedahan.com/blog/ReadingExcelFilesWithKoogra/Ionic.Utils.Zip.dll)
*/
using Koogra = Net.SourceForge.Koogra;
//Grab the workbook
Koogra.IWorkbook workbook = Koogra.WorkbookFactory.GetExcel2007Reader("ExcelWorkbook.xlsx");
@toinetoine
toinetoine / app.js
Created October 27, 2014 04:02
App.js for reading data from Mongo. From 'Building a RESTful API' (post at http://www.antoinedahan.com/blog/BuildingRESTfulAPI/)
/* express initialization */
var express = require('express');
var app = express();
/* body-parser initialization (use the body-parser json package) */
var bodyParser = require('body-parser');
app.use(bodyParser.json());
/* Main Router */
var ourApiRouter = express.Router();
@toinetoine
toinetoine / app.js
Last active August 29, 2015 14:08
App.js for reading data from Mysql. From 'Building a RESTful API' (post at http://www.antoinedahan.com/blog/BuildingRESTfulAPI/)
/* express initialization */
var express = require('express');
var app = express();
/* body-parser initialization (use the body-parser json package) */
var bodyParser = require('body-parser');
app.use(bodyParser.json());
/* Main Router */
var ourApiRouter = express.Router();
using System;
using System.Threading.Tasks;
using Microsoft.Owin;
using Owin;
[assembly: OwinStartup(typeof(SignalRExample.Startup))]
namespace SignalRExample
{
public class Startup
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Microsoft.AspNet.SignalR;
namespace SignalRExample.Hubs
{
public class ExampleHub : Hub
{
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Our Example Page for SignalR</title>
<!-- js files to include for SignalR-->
<script type="text/javascript" src="Scripts/jquery-2.1.3.min.js"></script>
<script src="Scripts/jquery.signalR-2.1.2.min.js"></script>
<script src="signalr/hubs"></script>
@toinetoine
toinetoine / goats.py
Last active August 29, 2015 14:22
Runs 1 million "Let’s Make a Deal" games (demonstrating the Monty Hall Paradox)
import random
# number of games to play
num_games = 1000000
# keeps track of wins that occur when using
# the selection-change-after-reveal strategy
reselect_win_tally = 0
for i in range(num_games):
import time
# calculate the domain (set of possible values) of the cell at (row, col)
def get_domain(board_state, row, col):
# initially state of the domain (cell can have any digit from 1-9)
domain = range(1, 10)
# eliminate illegal values from the domain based on the values in the cell's square
@toinetoine
toinetoine / email_domains.py
Last active September 9, 2015 00:00
Script to tally the domains of emails contained in the Ashley Madison email file
# write domain counts to file after every 1,000,000 emails read
increment_to_save = 1000000
def write_to_file(file_name, domains):
# sort the domains by count
from operator import itemgetter
domains = sorted(domains, key=itemgetter('count'))
# write the domains to the results file
results_file = open(file_name, "w")