Skip to content

Instantly share code, notes, and snippets.

View unimatrixZxero's full-sized avatar
🌱
💎

Sam Figueroa unimatrixZxero

🌱
💎
View GitHub Profile
@BiggerNoise
BiggerNoise / assign_case_command.rb
Created March 3, 2014 21:10
Command Pattern at work
class AssignCaseCommand < Command
attribute :case, Case
attribute :owner, User
attribute :created_by, User
attribute :comments, String
attribute :distribute_at, DateTime
attribute :distribute_rule_name, String
attribute :require_initial, Boolean
@paulosborne
paulosborne / gist:7640679
Created November 25, 2013 12:40
Hipster indexOf
var message = "hello, how are you Tal?";
if (~message.indexOf('Tal')) {
console.log('found matching text');
}
@jed
jed / how-to-set-up-stress-free-ssl-on-os-x.md
Last active February 25, 2024 17:35
How to set up stress-free SSL on an OS X development machine

How to set up stress-free SSL on an OS X development machine

One of the best ways to reduce complexity (read: stress) in web development is to minimize the differences between your development and production environments. After being frustrated by attempts to unify the approach to SSL on my local machine and in production, I searched for a workflow that would make the protocol invisible to me between all environments.

Most workflows make the following compromises:

  • Use HTTPS in production but HTTP locally. This is annoying because it makes the environments inconsistent, and the protocol choices leak up into the stack. For example, your web application needs to understand the underlying protocol when using the secure flag for cookies. If you don't get this right, your HTTP development server won't be able to read the cookies it writes, or worse, your HTTPS production server could pass sensitive cookies over an insecure connection.

  • Use production SSL certificates locally. This is annoying

Build your own private, encrypted, open-source Dropbox-esque sync folder

Prerequisites:

  • One or more clients running a UNIX-like OS. Examples are given for Ubuntu 12.04 LTS, although all software components are available for other platforms as well (e.g. OS X). YMMV
  • A cheap Ubuntu 12.04 VPS with storage. I recommend Backupsy, they offer 250GB storage for $5/month. Ask Google for coupon codes.

Software components used:

  • Unison for file synchronization
  • EncFS for folder encryption
@EpokK
EpokK / ngDatePicker.js
Last active December 19, 2015 23:59
ng-datePicker
angular.module('myApp', []).directive('ngDatePicker', function() {
return {
require: 'ngModel',
link: function(scope, element, attrs, ctrl) {
element.datepicker({
changeYear: true,
changeMonth: true,
appendText: '(yyyy-mm-dd)',
dateFormat: 'yy-mm-dd',
onSelect: function(dateText, inst) {
@afeld
afeld / gist:5704079
Last active November 27, 2023 15:43
Using Rails+Bower on Heroku
# scope uses merge which looses conditions when chained on the same attribute
# see https://github.com/rails/rails/issues/7365 for the issue
# see https://github.com/rails/rails/blob/da5e5c5f779355a2e99e63a90612cbeaeb0fc986/activerecord/lib/active_record/relation/spawn_methods.rb#L35 for an explanation
# see https://github.com/rails/rails/commit/cd26b6ae7c1546ef8f38302661bbedf8cb487311 for a fix in Rails 4
# The workaround is to just use class methods - we wrap a dsl around just that
# Usage: extend ChainableScope in your ActiveRecord::Base derived class
module ChainableScope
def chainable_scope name
raise 'chainable_scope must be called with a block!' unless block_given?
define_singleton_method name do |*args|
@orend
orend / gist:5134300
Created March 11, 2013 13:40
Streaming with csv, from ruby tapas
require 'csv'
def memstats
size = `ps -o size= #{$$}`.strip.to_i
end
memstats #4900
CSV.open('visitors.csv', headers: true) do |csv|
visitors = csv.each # Enumerator
memstats # 5164
@sj26
sj26 / assets.rake
Last active May 13, 2023 04:42
Don't discard cache during asset precompile. Full explanation and caveats: http://sj26.com/2013/02/09/the-asset-pipeline-isnt-actually-slow
# Stick this in lib/tasks/assets.rake or similar
#
# A bug was introduced in rails in 7f1a666d causing the whole application cache
# to be cleared everytime a precompile is run, but it is not neccesary and just
# slows down precompiling.
#
# Secondary consequences are the clearing of the whole cache, which if using
# the default file cache could cause an application level performance hit.
#
# This is already fixed in sprockets-rails for rails 4, but we patch here for
@internoma
internoma / style-desaturate.css
Created January 6, 2013 11:07
Desaturate & saturate css3
.desaturate {
filter: grayscale(100%); /* Current draft standard */
-webkit-filter: grayscale(100%); /* New WebKit */
-moz-filter: grayscale(100%);
-ms-filter: grayscale(100%);
-o-filter: grayscale(100%); /* Not yet supported in Gecko, Opera or IE */
filter: url(resources.svg#desaturate); /* Gecko */
filter: gray; /* IE */
-webkit-filter: grayscale(1); /* Old WebKit */
}