Skip to content

Instantly share code, notes, and snippets.

@ericelliott
ericelliott / chat-reducer-factories.js
Created August 28, 2016 03:04
Chat reducer test factories
const createChat = ({
id = 0,
msg = '',
user = 'Anonymous',
timeStamp = 1472322852680
} = {}) => ({
id, msg, user, timeStamp
});
const createState = ({
@turicas
turicas / description.md
Last active January 22, 2018 15:16
lxml deletes data from malformed HTML

I'm extracting data from a website and was testing some XPath expressions in Chrome Developer Tools (using $x(...) in console). After creating the expressions I need, I've automated the process using lxml to extract this data using Python. Problem: the number of results in lxml is different from the number I've got using Developer Tools! It seems lxml delete some data and adds a lot of </table> in the end (doing the process of loading the HTML into an lxml.html.Element and then extracting it using lxml.html.tostring results in completely different HTMLs - the majority of the data is removed). The HTML is attached in this gist (e-SIC.html) and the XPath is the following: //table[@class="padrao"]. I've tested the XPath in Developer Tools by executing the code in console: $x('//table[@class="padrao"]').length - it returns 2496.

@ejsuncy
ejsuncy / README.md
Last active April 6, 2018 13:08
View Chrome Websocket Frames as Formatted JSON
@myndzi
myndzi / gist:03eb5c42e8385470403c
Created June 21, 2014 17:22
How to use Sequelize with a UNIX domain socket
var sequelize = new Sequelize('postgres:/tmp');
var CM = sequelize.transactionManager.ConnectorManager;
sequelize.transactionManager.ConnectorManager = function (sequelize, config) {
var cm = new CM(sequelize, config);
cm.pg.defaults.database = 'database_name';
return cm;
}
sequelize.getQueryInterface().QueryGenerator
@thgaskell
thgaskell / gist:5987fccbd8473b5ef78f
Last active September 21, 2018 02:49
Introduction to Sequelize Migrations

What are Migrations

Just like how we use Git to version control source code, we use migrations to manage the state of our database schemas.

I'm not really sure what that means...

Imagine you're working on project with another developer, and you're both tasked with creating a specific part of an event planning application. Let's say you are in charge of creating the Users and your friend is going to create the Events.

Let's say you and your friend divided the work in a way so that neither of you will have to to use each other's code to finish your tasks. While you're working on your part of the application, you only really need to touch the Users table when you are working with the database.

Before you begin

Make sure that the project you are in is a node project (it has a package.json) and you have already installed and initialized sequelize (npm install --save sequelize, sequelize init). Also make sure that your config.json file has the correct credentials to connect to your database.

javascript:(function () {
//Served by rawgit: https://rawgit.com/
//From https://gist.github.com/theredpea/d08d5918a8c88889dfa26ad72dd17140#file-adapting_showobjectids-js
//To https://cdn.rawgit.com/theredpea/d08d5918a8c88889dfa26ad72dd17140/raw/9b32a0d0ac9e1a9cc85005fcbf83e20275d99fd4/adapting_showObjectIds.js
document.body.appendChild(document.createElement('script')).src = 'https://rawgit.com/abodelot/jquery.json-viewer/master/json-viewer/jquery.json-viewer.js';
var head = document.getElementsByTagName('head')[0];
$(document.createElement('link')).attr({
type: 'text/css',
href: 'https://rawgit.com/abodelot/jquery.json-viewer/master/json-viewer/jquery.json-viewer.css',
rel: 'stylesheet'
@springmeyer
springmeyer / bench.js
Created March 20, 2015 18:43
benchmark.js example: testing an async function
'use strict';
var path = require('path');
var fontnik = require('../');
var Benchmark = require('benchmark');
var opensans = path.resolve(__dirname + '/../fonts/open-sans/OpenSans-Regular.ttf');
var suite = new Benchmark.Suite();
@theredpea
theredpea / .block
Last active November 15, 2020 00:50
nate central limit theorem demo
license: mit
height: 2000
scrolling: yes
@afrex
afrex / Trailing Comma of Death regex
Created September 4, 2013 08:03
Use this regex in a search to retrieve trailing comma's of death within your application. This comma's will cause inconsistent behaviour in Internet Explorer browsers.
,\s*?\]|,\s+}
@LevelbossMike
LevelbossMike / d3.html
Created May 6, 2012 17:22
creating table from array of json with d3
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="http://mbostock.github.com/d3/d3.js"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
</head>
<body>
<table id="split">
<thead></thead>
<tbody></tbody>