Skip to content

Instantly share code, notes, and snippets.

@bonyiii
bonyiii / gist:1471379
Last active April 20, 2023 15:01
restore overwritten files linux
http://www.ehow.com/how_7517984_restore-overwritten-file-linux.html
Assess which partition on your computer you need to access to recover the files.
2
Unmount the directory using the "unmount" command in the interface. This will help prevent damaging the file you are trying to recover.
3
Type "debugfs" in the command line interface (all typing without quotation marks) and include the file system where the overwritten file is into the command. For example, typing "debugfs usr/personal" will bring up your personal directory. Hit "Enter" after typing the command.
4
@bonyiii
bonyiii / gist:822123
Created February 11, 2011 09:24
PostgreSQL BEFORE INSERT trigger with function
# Function returns user.login, current year, the primary_key which is the id, in 5 length (Example: 00045)
string format
# http://developer.postgresql.org/pgdocs/postgres/functions-formatting.html
# to_char(5,'00000') results the same number format
CREATE OR REPLACE FUNCTION "public"."function_name" () RETURNS trigger AS
'
BEGIN
NEW.title = (SELECT login FROM users WHERE id = NEW.author) || to_char(NOW(),\'YYYY\') || lpad(NEW.id::char, 5, \'0\');
RETURN NEW;
END
@bonyiii
bonyiii / gist:1247094
Created September 28, 2011 05:56
How to find and delete all hard links to a file
# http://linuxcommando.blogspot.com/2008/09/how-to-find-and-delete-all-hard-links.html
How to find and delete all hard links to a file
Deleting a file is deceptively simple. You can simply use the rm command like this.
$ rm file1
However, if the file has one or more hard links to it, life gets more interesting. You need to seek and destroy all hard links to the file.
@bonyiii
bonyiii / gist:2158289
Created March 22, 2012 13:14
Rails ajax link_to remote with put, post
http://www.kolodvor.net/2010/01/02/rails-csrf-and-ajax-requests/
http://api.rubyonrails.org/classes/ActionController/RequestForgeryProtection/ClassMethods.html#M000514
http://stackoverflow.com/questions/5241213/rails-session-is-blank-when-using-http-put
Key thing is to add form_authenticity_token to path param as a query_string
http://api.rubyonrails.org/classes/ActionView/Helpers/UrlHelper.html#method-i-link_to
<%= link_to 'Reset', null_counter_model_path(model, :authenticity_token => form_authenticity_token), :confirm => 'Are you sure?', :method => :put, :remote => true %>
@bonyiii
bonyiii / gist:884681
Created March 24, 2011 06:57
How to create diff file for gentoo ebuild patch

An example to patch unixODBC-2.3.0 on a 64bit machine to work with oracle 8.

First download unixODBC source. mkdir /tmp/unixODBC/source

Create two new folder. mkdir /tmp/unixODBC/patch/original mkdir /tmp/unixODBC/patch/unixODBC-2.3.0/DriverManager/

cp /tmp/unixODBC/source/unixODBC-2.3.0/DriverManager/SQLConnect.c /tmp/unixODBC/patch/original

@bonyiii
bonyiii / gist:1985562
Created March 6, 2012 10:21
How to make an activerecord model use a tempory table or view dynamically per query
# Creating view or temp table
ActiveRecord::Base.connection.execute("CREATE TEMPORARY TABLE users#{args.offset} SELECT * FROM users LIMIT #{limit} OFFSET #{(args.offset - 1) * limit}")
# or
ActiveRecord::Base.connection.execute("CREATE VIEW users#{args.offset} AS SELECT * FROM users LIMIT #{limit} OFFSET #{(args.offset - 1) * limit}")
### Giving relation back, suitable for find_in_batches
#User.arel_table.name ='users2'
# This changes table name in FROM part of the query
@bonyiii
bonyiii / gist:6184489
Created August 8, 2013 13:16
ruby multithread
http://speakmy.name/2013/04/02/concurrent-programming-and-threads-in-ruby-reading-list/
Concurrent Programming and Threads in Ruby - a reading list
02 April 2013
Many rubyists consider threads in Ruby as somewhat of an arcane knowledge, though in reality they’re a very well researched and understood concept. Of course, writing effective multithreaded concurrent programs requires certain amount of knowledge and discipline from the programmer, but there’s nothing that a smart one can’t learn if he wants to.
To help with the task, awesome @brainopia compiled a list of recommended reading on the topic of concurrency and threads. All kudos go to @brainopia, and the original list in Russian as available as a gist here:
@bonyiii
bonyiii / gist:1901621
Created February 24, 2012 15:24
mysqlreport explanation
Other great tool:
https://launchpad.net/mysql-tuning-primer
Hack MySQL ‹ mysqlreport ‹ Download ‹ Guide › Documentation
Blog Contact Sitemap
This web site is no longer maintained. Read why.
@bonyiii
bonyiii / start_rails_api.sh
Last active January 11, 2017 15:34
Start Rails Application
docker run -it \
--name sapi \
-p 3000:3000 \
--security-opt seccomp:chrome.seccomp.json \
-e DISPLAY=unix$DISPLAY \
-v /home/boni/public_html/app/my-api/gems:/usr/local/bundle \
-v /home/boni/public_html/app/my-api:/var/www/my-api \
-v /tmp/.X11-unix:/tmp/.X11-unix \
-v $HOME/Downloads:/home/dev/Downloads \
-v $HOME/.config/google-chrome/:/home/dev/data \
#!/bin/bash
set -e
case "$1" in
rails|rake|passenger)
# ensure the right database adapter is active in the Gemfile.lock
if [ -z "$NO_BUNDLE" ]; then
# bundle install --without development test
bundle install
chown dev:dev $GEM_HOME -R