Skip to content

Instantly share code, notes, and snippets.

View abhishek77in's full-sized avatar

Abhishek Srivastava abhishek77in

View GitHub Profile
@adamrdavid
adamrdavid / db_guidelines.md
Last active July 14, 2023 13:03
the darndest things
@blacktm
blacktm / install_ruby_rpi.sh
Last active February 28, 2024 23:24
A Bash script to install Ruby on the Raspberry Pi
#!/bin/bash
# --------------------------------------------------------------------------------------------
# Installs Ruby using rbenv/ruby-build on the Raspberry Pi (Raspbian)
#
# Run from the web:
# bash <(curl -s https://gist.githubusercontent.com/blacktm/8302741/raw/install_ruby_rpi.sh)
# --------------------------------------------------------------------------------------------
# Set the Ruby version you want to install
@stuartbain
stuartbain / subdomain_validator.rb
Last active October 25, 2021 22:33
Custom validator for Subdomains
class SubdomainValidator < ActiveModel::EachValidator
# http://matthewhutchinson.net/2010/10/27/rails-3-subdomain-validation-activemodeleachvalidator
def validate_each(object, attribute, value)
return unless value.present?
reserved_names = %w(www ftp mail pop smtp admin ssl sftp)
reserved_names = options[:reserved] if options[:reserved]
if reserved_names.include?(value)
object.errors[attribute] << 'cannot be a reserved name'
end
@zenorocha
zenorocha / .hyper.js
Last active November 12, 2023 15:13 — forked from millermedeiros/osx_setup.md
Setup macOS Sierra (10.12)
// Future versions of Hyper may add additional config options,
// which will not automatically be merged into this file.
// See https://hyper.is#cfg for all currently supported options.
module.exports = {
config: {
// default font size in pixels for all tabs
fontSize: 14,
// font family with optional fallbacks
@jasdeepsingh
jasdeepsingh / automate.rb
Created May 9, 2013 21:39
Scripting for Benefit
#!/usr/bin/ruby
require 'rubygems'
require 'net/http'
require 'uri'
require 'nokogiri'
require 'mail'
url = ###/tracktest.php
refnum = # my application reference number.
@floatingboxes
floatingboxes / jekyll_css_cache_bust.html
Last active May 13, 2021 07:47
CSS cache-bust technique for Jekyll
<!--
Stupid simple css cache bust for Jekyll using site generation timestamp year/month/day/hour/minute/seconds
Output example: v=20130403134355
-->
<link rel="stylesheet" href="/css/styles.css?v={{ site.time | date: '%Y%m%d%H%M%S' }}">
@mindreframer
mindreframer / list_starred_projects_for_somebody.rb
Created January 8, 2013 12:34
somebody's starred projects
require 'dbm'
require 'github_api'
class Cache
attr_accessor :db
def initialize
@db = DBM.open('starred', 666, DBM::WRCREAT)
end
def load(key)
@keighl
keighl / application.rb
Created December 19, 2012 16:42
Faster Rails asset precompilation via Capistrano .. just do it locally!
# Speed things up by not loading Rails env
config.assets.initialize_on_precompile = false
@moustafasamir
moustafasamir / gist:4250738
Created December 10, 2012 14:05
get facebook friends with picture using Koala
def get_facebook_friends(access_token)
@graph = Koala::Facebook::API.new(access_token)
friends = @graph.get_connections("me", "friends?fields=id,name,picture.type(large)")
return friends
end
@leemeichin
leemeichin / url_validator.rb
Created July 20, 2012 15:02
Rails Custom URL Validator
class UrlValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
record.errors[attribute] << (options[:message] || "must be a valid URL") unless url_valid?(value)
end
# a URL may be technically well-formed but may not actually be
# valid, so this checks for both.
def url_valid?(url)
url = URI.parse(url) rescue false
url.kind_of?(URI::HTTP) || url.kind_of?(URI::HTTPS)