Skip to content

Instantly share code, notes, and snippets.

module StringRGB
def rgb(r, g=nil, b=nil)
original = r
if g.nil?
# check for 'short' form values like 0x8cf and expand to 0x88ccff
if r < 4096
b = r & 0xf | (r << 4 & 0xf0)
g = (r >> 4 & 0xf) | (r & 0xf0)
r = (r >> 8 & 0xf) | (r >> 4 & 0xf0)
@scharfie
scharfie / packing-test.sh
Last active May 23, 2022 12:21
packing-test
#!/bin/bash
php << 'PHP'
<?php
$f = fopen("packing-test.php.dat", "wb");
$test = pack('A3d', 'Bob', 0);
fwrite($f, $test);
fclose($f);
PHP
# run with: rackup --host 0.0.0.0 dumper.ru
require 'bundler/inline'
gemfile do
source 'https://rubygems.org'
gem "shotgun"
gem "rack"
end
require 'json'
@scharfie
scharfie / block-contact-flickr.js
Last active March 15, 2016 21:59
A little script that adds one-click blocking of flickr contact from the "people who follow you" page (https://www.flickr.com/people/USERNAME/contacts/rev/)
/*
Script for the "Custom JavaScript" chrome extension (https://chrome.google.com/webstore/detail/custom-javascript-for-web/poakhlngfciodnhlhhgnaaelnpjljija)
*/
var BlockContact = function(contactId, callback) {
var magic_cookie = F.config.flickrAPI.auth_hash;
var data = {
magic_cookie: magic_cookie,
done: 1,
id: contactId,
redire: null,
use std::fmt;
struct NameBadge {
name: String
}
impl fmt::Display for NameBadge {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "Hello, my name is {}", self.name)
}
@scharfie
scharfie / devise.rb
Last active February 21, 2024 14:55
Autologin in development strategy for devise
# Reference(s):
# - http://kyan.com/blog/2013/10/11/devise-authentication-strategies
# - https://github.com/plataformatec/devise/blob/master/lib/devise/strategies/database_authenticatable.rb
module Devise
module Strategies
class Autologin < Authenticatable
def authenticate!
user = User.first
user ? success!(user) : fail!("No administrator account available")
end
@scharfie
scharfie / gist:a28d85cc6b524905dda1
Created June 22, 2015 19:17
QuickLook any text file and selectable text
echo "Enabling selectable text in quicklook..."
defaults write com.apple.finder QLEnableTextSelection -bool true; killall Finder
echo "Installing QLSteven for quicklook of text files..."
cd ~/Downloads
curl -o QLStephen.qlgenerator.1.4.2.zip "https://github.com/whomwah/qlstephen/releases/download/1.4.2/QLStephen.qlgenerator.1.4.2.zip"
unzip -o "QLStephen.qlgenerator.1.4.2.zip"
sudo cp -R QLStephen.qlgenerator /Library/QuickLook
qlmanage -r
@scharfie
scharfie / gist:aadf38e6ed1c4ab1a65a
Last active August 29, 2015 14:17
rbenv for ubuntu (.bashrc)
git clone https://github.com/sstephenson/rbenv.git ~/.rbenv
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(rbenv init -)"' >> ~/.bashrc
git clone https://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build
source ~/.bashrc
# example for ruby 2.2.2:
# rbenv install 2.2.2
# - then -
# rbenv local 2.2.2
# gem install bundler
@scharfie
scharfie / jira
Last active August 29, 2015 14:16 — forked from ssbarnea/jira
#!/bin/sh -e
# JIRA startup script
#chkconfig: 2345 80 05
#description: JIRA
# Define some variables
# Name of app ( JIRA, Confluence, etc )
APP=jira
# Name of the user to run as