Skip to content

Instantly share code, notes, and snippets.

@stefanhendriks
stefanhendriks / cookieshelper.cs
Last active June 4, 2023 17:14
A cookies helper class to easily read and set cookies on HttpRequest (Asp.Net Core)
public class CookiesHelper
{
// Inspired from:
// https://github.com/aspnet/Mvc/blob/538cd9c19121f8d3171cbfddd5d842cbb756df3e/test/Microsoft.AspNet.Mvc.FunctionalTests/TempDataTest.cs#L201-L202
public static IDictionary<string, string> ExtractCookiesFromResponse(HttpResponseMessage response)
{
IDictionary<string, string> result = new Dictionary<string, string>();
IEnumerable<string> values;
@prusswan
prusswan / gist:5703074
Last active December 18, 2015 01:19
Ruby and Rails offline docs generation
# rails
sdoc -x test -x example -x bin -N --main rails-3.2.13/README.rdoc --title "Rails 3.2.13" --op ~/Desktop/rails-3.2.13 rails-3.2.13
# ruby (rbenv)
sdoc --main ruby-1.9.3-p392/README -x test -x example -x bin -N --title "Ruby 1.9.3" --op ~/Desktop/ruby-1.9.3 ~/.rbenv/sources/1.9.3-p392/ruby-1.9.3-p392 ~/.rbenv/sources/1.9.3-p392/ruby-1.9.3-p392/README
sdoc --main ruby-1.9.3-p392/README -x test -x example -x bin -N --title "Ruby 1.9.3" --op ~/Desktop/ruby-1.9.3 ruby-1.9.3-p392 ruby-1.9.3-p392/README
# not working yet
sdoc --main ruby-2.0.0-p195/README -x test -x example -x bin -N --title "Ruby 2.0.0" --op ~/Desktop/ruby-2.0.0 ~/.rbenv/sources/2.0.0-p195/ruby-2.0.0-p195 ~/.rbenv/sources/2.0.0-p195/ruby-2.0.0-p195/README

Security is Hard

Massive Assignment

  • watch for ActiveRecord Relation, like has_many, has_many :through
  • watch for user_roles, `group_users
  • UPDATE action

Admin

@dergachev
dergachev / GIF-Screencast-OSX.md
Last active November 5, 2024 18:44
OS X Screencast to animated GIF

OS X Screencast to animated GIF

This gist shows how to create a GIF screencast using only free OS X tools: QuickTime, ffmpeg, and gifsicle.

Screencapture GIF

Instructions

To capture the video (filesize: 19MB), using the free "QuickTime Player" application:

@dwbutler
dwbutler / private_protected.rb
Last active September 3, 2018 07:59
Demonstrates behavior of private and protected methods in child classes in Ruby (including some surprising behavior and pitfalls)
# Tested in Ruby 1.8.7
class ParentClass
def call_private_good
# Private methods can only be called without an explicit receiver
private_test
end
def call_private_bad
# Calling a private method with an explicit receiver (self) will fail
@raws
raws / 01-install.txt
Created November 23, 2012 03:34
Install Ruby 1.9.3-p327 on a Synology DS1511+ with DSM 4.1
#########################################
### Install wget-ssl over ipkg's wget ###
#########################################
$ ipkg install -verbose_wget libidn # To get ipk URL
$ ipkg install -verbose_wget wget-ssl # To get ipk URL
$ /usr/syno/bin/wget http://ipkg.nslu2-linux.org/feeds/optware/syno-i686/cross/unstable/libidn_1.25-1_i686.ipk
$ /usr/syno/bin/wget http://ipkg.nslu2-linux.org/feeds/optware/syno-i686/cross/unstable/wget-ssl_1.12-2_i686.ipk
$ ipkg install libidn_1.25-1_i686.ipk
$ ipkg install wget-ssl_1.12-2_i686.ipk
@clyfe
clyfe / cancan.rb
Last active September 29, 2015 01:07
Monkey patch for CanCan 1.6.7, replaces MetaWhere with Squeel and more
# Setup
# =====
#
# Put this gist in Rails.root/config/initializers/cancan.rb
# Add Squeel to Gemfile, see https://github.com/ernie/squeel
#
# gem "squeel", "~> 0.9.3"
#
# Load Squeel hash and symbol extensions in squeel config initializer
#
@grosser
grosser / gist:1168961
Created August 24, 2011 19:30 — forked from zeke/gist:20844
# drop this in a ruby file in my_rails_app/config/initializers
# restart your rails and app you're good to go!
class String
# remove middle from strings exceeding max length.
def ellipsize(options={})
max = options[:max] || 40
delimiter = options[:delimiter] || "..."
return self if self.size <= max
remainder = max - delimiter.size
@javan
javan / gist:1168475
Created August 24, 2011 16:32
Fix iPhone home button
Found this tip in comment here: http://www.tipb.com/2011/01/04/tipb-bug-home-button-working-iphone/
1.) Open any application
2.) Press and hold the power button until the slide to shutdown swipe bar appears.
3.) Release Power button
4.) Press and hold Home button Lightly
until screen returns to icon screen
@philsmy
philsmy / arel_or.rb
Created August 18, 2011 10:20
or scopes - add this to your model to be able to or scopes together (eg: Model.or(Model.scope1, Model.scope2). Stolen and adapted from fake_arel
__or_fn = lambda do |*scopes|
where = []
joins = []
includes = []
# for some reason, flatten is actually executing the scope
scopes = scopes[0] if scopes.size == 1
scopes.each do |s|
w = []
s.where_clauses.each do |where_clause|