Skip to content

Instantly share code, notes, and snippets.

Ka Mok kamok

View GitHub Profile
@kamok
kamok / gist:36d91e3a3c9c5b73a964829a2ee6f707
Created Sep 22, 2019
Script you paste in console of Chrome History to bulk delete queried history (has limitations!)
View gist:36d91e3a3c9c5b73a964829a2ee6f707
var historyItems = document.querySelector('#history-app').shadowRoot.querySelector('#main-container').querySelector('#history').shadowRoot.querySelector('iron-list').querySelectorAll('history-item')
var checkEvent = document.createEvent("HTMLEvents");
checkEvent.initEvent('change', false, true);
var clickEvent = document.createEvent("HTMLEvents");
clickEvent.initEvent("click", false, true);
// Only if the item is not hidden, check the item
historyItems.forEach((item) => {
View people.controller.ts
import restify = require('restify');
import axios, { AxiosResponse } from 'axios';
import { pick, keys } from 'lodash';
export class PeopleController {
search(req: restify.Request, res: restify.Response, next: restify.Next) {
const query = PeopleController.buildQuery(req.query);
if (query) {
return axios.get('http://localhost:8983/solr/mycollection2/select?q=' + query).then(
(solrRes: AxiosResponse) => {
res.json(200, solrRes.data);
View import.controller.ts
import restify = require('restify');
import { CASSANDRA_CLIENT } from '../../cassandra-client';
import { types } from 'cassandra-driver';
import axios, { AxiosRequestConfig, AxiosResponse } from 'axios';
export class ImportController {
importPeople(_: restify.Request, res: restify.Response, next: restify.Next) {
const query = 'SELECT * FROM people'; // TODO, partial query
CASSANDRA_CLIENT.execute(query)
View people.json
[
{
"_id": "5bf30f5d60d07b82f306900e",
"index": 0,
"guid": "1611af64-03c1-494d-a02d-d7e4cceafb18",
"isActive": false,
"balance": "$1,470.41",
"age": 10,
"eyeColor": "brown",
"name": "Bauer Moran",
View cassandra-client.ts
import cassandra = require('cassandra-driver');
import peopleData from './seed/people.json';
export class CassandraClient {
client: cassandra.Client;
constructor() {
this.client = new cassandra.Client({ contactPoints: ['127.0.0.1:9042'], keyspace: 'cassandrasolr' });
this.seedData();
}
View config.ts
export interface Config {
name: string;
port: string;
env: string;
version: string;
}
const port = process.env.NODE_PORT || '3000';
const env = process.env.NODE_ENV || 'development';
@kamok
kamok / health.routes.ts
Last active Nov 19, 2018
/src/controllers/health/health.routes.ts
View health.routes.ts
import restify = require('restify');
import { HealthController } from './health.controller';
const healthRoute = (api: restify.Server) => {
const routeCtrl = new HealthController();
api.get('/health', routeCtrl.get);
};
module.exports.routes = healthRoute;
@kamok
kamok / health.controller.ts
Created Nov 19, 2018
src/controllers/health/health.controller.ts
View health.controller.ts
import restify = require('restify');
export class HealthController {
get(req: restify.Request, res: restify.Response, next: restify.Next) {
res.json(200, 'beep boop');
return next();
}
}
View app.ts
import fs = require('fs');
import restify = require('restify');
import { settings } from './config';
const api = restify.createServer({ name: settings.name });
import corsMiddleware = require('restify-cors-middleware');
const cors = corsMiddleware({
preflightMaxAge: 5,
origins: ['http://api.myapp.com', 'http://web.myapp.com'], // to configure
@kamok
kamok / sample.rb
Created Sep 5, 2016
Example of almost spoken-language syntax in Ruby
View sample.rb
def self.fetch_or_solve(puzzle)
if sudoku = Sudoku.find_by(puzzle: puzzle)
return sudoku.solution
else
solution = Sudoku.solve(puzzle)
end
if solution != false
Sudoku.create(puzzle: puzzle, solution: solution).save
end
You can’t perform that action at this time.