Skip to content

Instantly share code, notes, and snippets.

View sslotsky's full-sized avatar
🌶️
Working from home

Sam Slotsky sslotsky

🌶️
Working from home
View GitHub Profile
@sslotsky
sslotsky / search_concatenated.rb
Created March 22, 2013 16:26
Use search text to search on a concatenation of db fields.
def self.text_search text = ''
scope = self.scoped
if text.squish!.present?
conditions = []
conditions << sanitize_sql_array(["surveys_large_clinic_individual_compensation_answers.physician_id ILIKE ?", "%#{text}%"])
conditions << sanitize_sql_array(["surveys_large_clinic_individual_compensation_answers.specialty_name ILIKE ?", "%#{text}%"])
conditions << sanitize_sql_array(["org_search.name ILIKE ?", "%#{text}%"])
concat_string = "(surveys_large_clinic_individual_compensation_answers.organization_id || '-'" +
" || surveys_large_clinic_individual_compensation_answers.specialty_id || '-'" +
public class ChatRoom
{
[Key]
public Guid ID { get; set; }
public virtual ICollection<Message> Messages { get; set; }
}
public static class ChatRoomExtensions
{
public IQueryable<ChatRoom> WithMessagesFromUser(this IQueryable<ChatRoom> queryable, Guid userID)
@sslotsky
sslotsky / ChatRoomService.cs
Last active August 29, 2015 14:27
Services as controller properties in a Resource Oriented Architecture
public class ChatRoomService : Service<ChatRoom>
{
public ChatRoomService(string connectionString) : base(connectionString) { }
public override DbSet<ChatRoom> Relation(ChatDbContext context)
{
return context.ChatRooms;
}
}
class Item {
public int Id;
public ArrayList<int> TransactionIds;
}
class Node {
public ArrayList<Item> Items;
public ArrayList<Node> Children = new ArrayList<Node>();
public Node(ArrayList<Item> items) {
<html>
<head>
<script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/knockout/knockout-3.3.0.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.3/underscore-min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" integrity="sha512-dTfge/zgoMYpP7QbHy4gWMEGsbsdZeCXz7irItjcC3sPUFtf0kuFbDz/ixG7ArTxmDjLXDmezHubeNikyKGVyQ==" crossorigin="anonymous">
</head>
<body>
<div id="foo" class="container">
<div data-bind="foreach: bars">
<div class="row">
@sslotsky
sslotsky / md.html
Created November 8, 2015 06:41
Simple knockout example shows markdown text on the right as you enter text on the left
<html>
<head>
<script src="./marked.js"></script>
<script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/knockout/knockout-3.3.0.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<link rel="stylesheet" href="./tomorrow-night-eighties.css">
<script src="http://cdn.jsdelivr.net/highlight.js/8.9.1/highlight.min.js"></script>
<style>
#marked pre {
word-wrap: normal;
import React from "react";
import { initialize } from "apothecary";
import { Bridge } from "react-apothecary";
const store = initialize({ n: 1 });
...
export default () => (
<Bridge store={store}>
import { initialize, split } from "apothecary";
const store = initialize({ n: 1 });
const increment = step => split(n => n + step, "n");
const decrement = step => split(n => n - step, "n");
...
import { initialize, split } from "apothecary";
import { tunnel, fromProps } from "react-apothecary";
const store = initialize({ n: 1 });
const increment = step => split(n => n + step, "n");
const decrement = step => split(n => n - step, "n");
...
import { initialize, split } from "apothecary";
import { tunnel, fromProps } from "react-apothecary";
const store = initialize({ n: 1 });
const increment = step => split(n => n + step, "n");
const decrement = step => split(n => n - step, "n");
...