Skip to content

Instantly share code, notes, and snippets.

View jacobmendoza's full-sized avatar
🏠
Working from home

Jacob jacobmendoza

🏠
Working from home
View GitHub Profile
@jacobmendoza
jacobmendoza / s-expression.txt
Last active March 14, 2016 19:28
S-expression example
[:program, [:stmts_add, [:stmts_new], [:method_add_block, [:command_call, [:var_ref, [:@const, "RSpec", [1, 0]]], :".",
[:@ident, "describe", [1, 6]], [:args_add_block, [:args_add, [:args_new], [:var_ref, [:@const, "Something", [1, 15]]]],
false]], [:do_block, nil, [:stmts_add, [:stmts_new], [:method_add_block, [:command, [:@ident, "describe", [2, 2]],
[:args_add_block, [:args_add, [:args_new], [:string_literal, [:string_add, [:string_content], [:@tstring_content,
"when creating the handler", [2, 12]]]]], false]], [:do_block, nil, [:stmts_add, [:stmts_new], [:method_add_block,
[:command, [:@ident, "it", [3, 4]], [:args_add_block, [:args_add, [:args_new], [:string_literal, [:string_add,
[:string_content], [:@tstring_content, "fails if no tweet has been provided", [3, 8]]]]], false]], [:do_block, nil,
[:stmts_add, [:stmts_new], [:command_call, [:method_add_arg, [:fcall, [:@ident, "expect", [4, 6]]], [:arg_paren,
[:args_add_block, [:args_add, [:args_new], [:@int, "0", [4, 13]]], false]]], :".", [:@ident,
RSpec.describe SUT do
describe 'when the sut does something' do
it 'works as expected' do
expect(1).to be 1
end
end
end
@jacobmendoza
jacobmendoza / Cacheability.cs
Last active September 2, 2015 10:00 — forked from bradwilson/Cacheability.cs
Using chaining to create cached results in ASP.NET Web API v2
public enum Cacheability
{
NoCache,
Private,
Public,
}
private class ST
{
public int Id { get; set; }
public string Name { get; set; }
}
public void ProcessChildCategories(XElement categoriesNode, Category parentNode)
{
var xmlCategories = categoriesNode.Elements("Category");
@jacobmendoza
jacobmendoza / fast-csv-parsing.cs
Last active August 29, 2015 13:57
Fast CSV parsing for NopCommerce provinces
// This script assumes unique Abbreviation field.
const int countryId = 72;
var sql =
@"IF NOT EXISTS (SELECT 1 FROM StateProvince WHERE Abbreviation = '{2}')
BEGIN
INSERT StateProvince (CountryId, Name, Abbreviation, Published, DisplayOrder) VALUES ({0}, '{1}', '{2}', {3}, {4})
END;";
@jacobmendoza
jacobmendoza / log.js
Created November 20, 2012 10:59 — forked from cowboy/log.js
JavaScript: log= (insanity?)
/*
* log= (insanity?)
* http://benalman.com/
*
* Copyright (c) 2012 "Cowboy" Ben Alman
* Licensed under the MIT license.
*/
Object.defineProperty(global, 'log', {
set: function(args) {
@jacobmendoza
jacobmendoza / CanvasClockExperiment.js
Created November 13, 2012 20:51
Canvas clock experiment
<html>
<head>
<script type="application/javascript">
var _context = null;
var _counterIdentifier = null;
var _counterState = 0;
function startCounter() {
if (canvas.getContext) {
_context = canvas.getContext("2d");
@jacobmendoza
jacobmendoza / BaseRequestInWebApi.cs
Created November 8, 2012 12:57
Access to base request in WebApi to retrieve client IP
var baseRequest = ((HttpContextWrapper)request.Properties["MS_HttpContext"]).Request;
var remoteDir = baseRequest.ServerVariables["REMOTE_ADDR"];
var directionsOfRedirection = baseRequest.ServerVariables["X_FORWARDED_FOR"];
return remoteDir ?? directionsOfRedirection;
@jacobmendoza
jacobmendoza / HTML5BezierExperiment.js
Created November 6, 2012 12:14
HTML5 Bezier experiment
<html>
<head>
<script type="application/javascript">
var _context = null;
var _counter = 0;
var _maxIterations = 15;
var _current_x_position = 0;
var _current_y_position = 384;
function draw() {
@jacobmendoza
jacobmendoza / MotorPlantillasSimple.cs
Created October 26, 2012 08:43
El motor de plantillas más simple del mundo
private string ObjectToTextTemplate(string text, object objectToSerialize)
{
const string enclosingSymbol = "#";
const string entityProxyModule = "EntityProxyModule";
var type = objectToSerialize.GetType();
var isEntityFrameworkProxyObject = type.Module.ScopeName.Contains(entityProxyModule);
foreach (var propertyInfo in type.GetProperties())
{