Skip to content

Instantly share code, notes, and snippets.

View gist:531fbf004b80961521da
<!DOCTYPE html><html class="no-touch" lang="en"><head><meta charset="utf-8" /><title>Mobile first web app theme | first</title><meta content="mobile first, app, web app, responsive, admin dashboard, flat, flat ui" name="description" /><meta content="width=device-width, initial-scale=1, maximum-scale=1" name="viewport" /><link rel="stylesheet" media="all" href="/assets/bootstrap.css?body=1" />
<link rel="stylesheet" media="all" href="/assets/font-awesome.min.css?body=1" />
<link rel="stylesheet" media="all" href="/assets/font.css?body=1" />
<link rel="stylesheet" media="all" href="/assets/plugin.css?body=1" />
<link rel="stylesheet" media="all" href="/assets/style.css?body=1" />
<link rel="stylesheet" media="all" href="/assets/landing.css?body=1" />
<link rel="stylesheet" media="all" href="/assets/app.css?body=1" />
<link rel="stylesheet" media="all" href="/assets/application.css?body=1" /><script src="/assets/jquery.js?body=1"></script>
<script src="/assets/angular.js?body=1"></script>
<script src="/assets/an
View gist:6d4131a91f80a3fdbb1a
var rBusApp = angular.module('rBusApp', ['restangular','ui.router']);
rBusApp.config(["$stateProvider", "$urlRouterProvider", function($stateProvider, $urlRouterProvider) {
$urlRouterProvider.otherwise('/');
$stateProvider.
state('index',
{url: '/', templateUrl: "landing.html", controller: 'landingController'}
).
state('routes',
View gist:6d10ab0a0fd8ab1c8791
doctype html
html.no-touch[lang="en"]
head
meta[charset="utf-8"]
title
| Mobile first web app theme | first
meta[name="description" content="mobile first, app, web app, responsive, admin dashboard, flat, flat ui"]
meta[name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"]
= stylesheet_link_tag 'application', media: 'all'
= javascript_include_tag 'application'
@svs
svs / gist:7fc59be7b4b0cc68b699
Last active Aug 1, 2019
Too Many `a`s (with apologies to Dr Seuss)
View gist:7fc59be7b4b0cc68b699
(Original here http://www.poetryfoundation.org/poem/171612)
Did I ever tell you that Programmer McCave
Had twenty-three variables and he named them all `a`
Well, he did. And that wasn't a smart thing to do.
You see, when he wants wants to add `a` to 2
He doesn't get a number oh no no no
All twenty-three `a`s cause a buffer overflow
View aws_struct.rb
require 'rspec'
require 'aws-sdk-core'
require 'awesome_print'
require 'pry-byebug'
ks = [:creation_date, :name]
class AwsResponse < Struct.new(*ks)
end
View gist:8780376
# why not?
def power(n)
2 ** n
end
# if you must do it the brute force way
def power(n)
return 1 if n == 0
(1..[0,n-1].max).reduce(2) { |acc, n| acc * 2 }
end
View multiupdate.rb
# Given a table stat with primary key "slug" with data
# [{slug: 'foo', stats: {}}, {slug:'bar', stats:{}}]
updated_stats = {
'foo' => {a: 1, b: 2},
'bar' => {a: 3, b: 4}
}
# I can do this
updated_stats.each{|k,v|
View find_bal.rb
#Given an array of numbers i.e. [1,2,3...1000], find out all possible combinations that add up to any given number i.e. 51437
#start with empty db
# start with 1st transaction -> write {key = 1, value => 1 }
# for the second transaction write { key => 1.2 => value => 3 }
# { key = 2, value => 3 }
# for the third transaction write { key => 1.2.3 => value => 6 }
# { key = 1.3, value => 4 }
# { key = 2.3, value => 5 }
# { key = 3, value => 3 }
View death_of_ifs.rb
# Assuming your execute command is more complex than a simple puts,
# you will need separate classes
class GoodbyeCommand
def execute
# complex logic here
end
end
class TwitterCommand
View games_controller.rb
module GamesController
class Index < ControllerAction
def get
[200, {}, Game.all.to_json]
end
def params
super.except(:deleted_at) # no need for strong_params. specify what goes and what doesn't by overriding the params