Skip to content

Instantly share code, notes, and snippets.

@foysavas
foysavas / ask-chatgpt
Created June 6, 2023 20:27
ask-chatgpt from the command line
#!/bin/bash
## Based on a script from @chrishwiggins
## https://github.com/chrishwiggins/mise/blob/9bc3e8c6ae309db3fb3e9f0e21d38925f06af82e/bash/oai-no-key.sh
if [ $# -eq 0 ]; then
echo "Usage: ask-chatgpt \"your questions\"" >&2
exit 1
fi
@foysavas
foysavas / .direnvrc
Created May 15, 2023 17:44
direnv use_nvm
use_nvm()
{
local version
version="${1}"
if [[ -e .node-version ]]; then version=$(<.node-version)
elif [[ -e .nvmrc ]]; then version=$(<.nvmrc)
fi
if [[ -e ~/.nvm/nvm.sh ]]; then
source ~/.nvm/nvm.sh
@foysavas
foysavas / dokku-notes.sh
Last active August 29, 2015 14:11
dokku notes
# install dokku on ubuntu 14.04 server
wget -qO- https://raw.github.com/progrium/dokku/v0.3.9/bootstrap.sh | sudo DOKKU_TAG=v0.3.9 bash
# add application on server
dokku apps:create the-app
# add developer public key
cat developers_id_rsa.pub | ssh ubuntu@the-dokku-server "sudo sshcommand acl-add dokku $USER"
# developer attaches dokku to local git repo
@foysavas
foysavas / gist:53b5cf742f5c4b374386
Created July 22, 2014 15:33
Putnam 2013 Problem B6
http://inside-bigdata.com/2014/07/20/putnam-mathematical-competitions-unsolved-problem/
All final boards are full of stones (LAAEFTR).
A turn can only net 0 or 1 stones (LAAEFTR).
Only the removal of an edge stone nets 0 stone (LAAEFTR).
The removal of an edge stone is always optional (LAAEFTR).
A stone adjacent to a stone cannot be removed (LAAEFTR).
Since A plays first on an odd sized board, an even number of spots are left over, meaning A will win unless B plays a turn that nets 0 stones.
If A's first move is anywhere but at the edge with subsequent moves building a chain of stones outward, B will only be able to play a net 0 stone turn on a self-laid edge stone.
@foysavas
foysavas / timer.react
Created February 13, 2014 20:22
template example for react.js
var Timer = React.createClass({
getInitialState: function() {
return {secondsElapsed: 0};
},
tick: function() {
this.setState({secondsElapsed: this.state.secondsElapsed + 1});
},
componentDidMount: function() {
this.interval = setInterval(this.tick, 1000);
},
@foysavas
foysavas / gist:3369638
Created August 16, 2012 11:59
_params.js
_params = function(params,encoded) {
var __hasProp = {}.hasOwnProperty;
maybeEncode = function(k){ return (encoded ? encodeURIComponent(k) : k); }
var pairs, proc;
pairs = [];
(proc = function(object, prefix) {
var el, i, key, value, _results;
if (object == null) object = params;
if (prefix == null) prefix = null;
_results = [];
@foysavas
foysavas / Rakefile
Created July 11, 2012 18:16
LastFailed for RSpec
namespace :spec do
require './last_failed_logger.rb'
default_opts = ["--format progress", "--color", "--fail-fast", "-f LastFailedLogger"]
RSpec::Core::RakeTask.new(:auto) do |t|
if File.exists? "./log/last_failed_spec.log"
$ran_last_failed_test = true
t.rspec_opts = [*default_opts, "--tag ~wip"]
t.pattern = File.open("./log/last_failed_spec.log").read
@foysavas
foysavas / haml_converter.rb
Created February 29, 2012 17:45 — forked from radamant/haml_converter.rb
Haml, Sass, and Scss conversion for jekyll
module Jekyll
require 'haml'
class HamlConverter < Converter
safe true
priority :low
def matches(ext)
ext =~ /haml/i
end
@foysavas
foysavas / helpers.rb
Created January 31, 2011 18:12
Carrierwave, DataMapper, & Sinatra starring in "Imagine the Possibilities"
def is_ajax_request?
if respond_to? :content_type
if request.xhr?
true
else
false
end
else
false
end
class ApplicationController < ActionController::Base
before_filter :compound_date_values
protected
def compound_date_values(h=params,prefix=[])
to_fix = {}
h.each do |k, v|
if v.is_a? Hash