Skip to content

Instantly share code, notes, and snippets.

View hardboiled's full-sized avatar

Daniel Ege hardboiled

View GitHub Profile
@hardboiled
hardboiled / game_destroyed
Created December 16, 2011 21:15
Destroy Game without score when Team is destroyed
# On branch master
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# modified: app/controllers/memberships_controller.rb
# modified: app/controllers/teams_controller.rb
# modified: app/models/game.rb
# modified: app/models/team.rb
# modified: spec/requests/results_spec.rb
#
@hardboiled
hardboiled / profile.rb
Last active August 29, 2015 14:18
Profile a code block
# returns number of seconds elapsed on average for block execution
def profile(num_times, idx, &block)
profile_arr = []
num_times.times do
beginning = Time.now
block.call(idx)
idx+=1
profile_arr << Time.now - beginning
end
profile_arr.reduce(:+).to_f / profile_arr.size
@hardboiled
hardboiled / curl.md
Last active November 16, 2021 18:31

Curl Tutorial

Curl is free open source software that is used for making HTTP(S) requests. It's pre-installed on a variety of non-windows platforms and is supported on almost all operating systems, including Windows. It's particularly useful for debugging APIs, as testers and developers can use identical commands for reproducing issues without the need for screenshots or browsers or any other intermediate technology. Below is a short tutorial to cover most use-cases.

Basic examples

curl www.google.com #returns just the body of the HTTP request

curl -i "www.google.com" #returns the body plus the HTTP headers

curl -v "www.google.com" > /dev/null #(*nix only) HTTP headers without body

@hardboiled
hardboiled / globally-responding-to-async-requests.js
Created February 25, 2016 15:22
This is a JS snippet similar to one that I wrote for an optimizely experiment that needed up update button text everytime a new set of products on our site was fetched. The markup would render and then my callback would replace the text for the users in the experiment.
yourCb = function(){
console.log('hello world');
};
jQuery(function(){
var w$ = window.$;
var oldAjax = w$.ajax;
w$.ajax = function(settings){
var url = (typeof settings === "string") && settings;
var success = null;
namespace MyRestApi.Filters
{
public class ValidateStateAttribute : ActionFilterAttribute, IActionFilter
{
public override void OnActionExecuting(HttpActionContext actionContext)
{
if (!actionContext.ModelState.IsValid)
{
var dict = new List<object>();
//Loop through each "model"/"contract" attribute, and return the error with a 422 status with the error messages.
$ ls wedding_registries*
wedding_registries_20161103.csv wedding_registries_20161115.csv
$ ls baby_registries*
baby_registries_20161104.csv baby_registries_20161115.csv
$ ls {baby,wedding}_registries*
baby_registries_20161104.csv wedding_registries_20161103.csv
baby_registries_20161115.csv wedding_registries_20161115.csv
{
"startedDateTime": "2016-12-16T20:16:03.865Z",
"time": 976.1639999996987,
"request": {
"method": "POST",
"url": "https://uploads.stripe.com/v1/files",
"httpVersion": "HTTP/1.1",
"headers": [
{
"name": "Pragma",
@hardboiled
hardboiled / s3-bucket-wide-encryption.md
Last active August 8, 2023 09:55
Describes How to Upload Only Encrypted Files to s3

s3 file encryption

s3 supports encryption at rest, but there isn't an option in s3 that automatically encrypts all files that are uploaded, so you need to specify encryption manually when you upload them.

how to force server-side encryption when uploading to s3

I normally upload files to s3 from the CLI like so using the --sse AES256 flag:

aws s3 cp ./your-local-file.txt \
 s3:////your-local-file.txt \
//usage of interface
clientInterfaceInstance.trigger('window-focus', screen.width, screen.height)
//definitions
class ClientInterface {
initialize(client) {
this.client = client;
}
//public function
trigger(event) {
#/bin/bash
# usage: $PID=<process_id_to_wait_on> $SCRIPT=<script_to_run_after_process_exits> sh ./run-script-on-process-complete.sh
STR="$(ps -opid | grep $PID | grep -v grep)"
echo $STR
while [ "$STR" = "$PID" ]; do
sleep 1;
STR=`ps -opid | grep $PID | grep -v grep`
done
sh $SCRIPT 2 > errors.log > output.log