Skip to content

Instantly share code, notes, and snippets.

View noriyotcp's full-sized avatar

Noriyo Akita noriyotcp

View GitHub Profile
search-repo() {
if [ ${#} -eq 0 ]; then
echo "No args: source-repo <path/to/dir>"
else
for _ in $(seq 1 ${#}) # Loop for the number of arguments
do
# pass the 1st argument to the following command
find "${1}" -type d -exec test -e '{}/.git' ';' -print -prune
shift
done
@noriyotcp
noriyotcp / 000.md
Created September 13, 2019 13:44 — forked from Papierkorb/000.md
Memory Management code taken from my Crystal OS project (AMD64!).

Hello there

This code comes from my operating system project, written in Crystal. The target platform was AMD64, so that's why it uses 64-Bit integers all over the place. The whole thing isn't open (yet?), but I stopped working on it so..

Take what you want from it, however a short source description, e.g. using a in-source comment, to this gist or to me would be really neat :)

@noriyotcp
noriyotcp / 000_HOWTO.md
Last active September 13, 2019 06:48 — forked from Papierkorb/000_HOWTO.md
Dynamic library in Crystal #crystal

Writing a dynamic library in Crystal, and calling it from C

  • Download all files.
  • Build the Crystal part:
crystal build --release --cross-compile --prelude ./no_main library.cr
              ^ You can leave this out
                        ^ We want to link ourselves!
 ^ Use our custom prelude!
@noriyotcp
noriyotcp / pthread_sample.cr
Created June 25, 2017 16:32
[Crystal] - LibC pthread sample
# I referred to:
# https://github.com/crystal-lang/crystal/issues/1967#issuecomment-167261460
print_message_function = -> (message : Void*) do
puts Box(String).unbox(message)
return Pointer(Void).null
end
thread1 = uninitialized LibC::PthreadT
thread2 = uninitialized LibC::PthreadT
message1 = "Thread 1"

What's this PR do?

Where should the reviewer start?

How should this be manually tested?

Any background context you want to provide?

What are the relevant tickets?

Screenshots (if appropriate)

Questions:

  • Is there a blog post?
  • Does the knowledge base need an update?
  • Does this add new (Python) dependencies which need to be added to chef?
@noriyotcp
noriyotcp / memcpy.cr
Last active December 27, 2016 23:19
memcpy example
def memcpy(s1 : Void*, s2 : Void*, size : UInt32) : Void*
dest : Char* = s1.as(Char*)
src : Char * = s2.as(Char*)
(0...size).each do |i|
dest[i] = src[i]
end
return s1
end
buf1 = ['A', 'B', 'C', 'D', 'E'] of Char
@noriyotcp
noriyotcp / 0_reuse_code.js
Created December 10, 2016 07:58
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@noriyotcp
noriyotcp / gnomesort.cr
Last active December 2, 2016 14:45
Gnome Sort and Merge Sort in Crystal
# Python version in Python Algorithms, Listing 3-1
# http://www.apress.com/us/book/9781484200568
def gnomesort(seq)
i = 0
while i < seq.size
if i == 0 || seq[i-1] <= seq[i]
i += 1
else
seq[i], seq[i-1] = seq[i-1], seq[i]
@noriyotcp
noriyotcp / _sidebar.html.erb
Created November 20, 2015 08:22
[Ruby on Rails] A helper method to add active class to list items
<!-- there's Admin::CountriesController -->
<ul>
<li class="<%= active_class('admin/countries') %>">
<%= link_to ... %>
</li>
.
.
.
</ul>
@noriyotcp
noriyotcp / foo_model.rb
Created November 5, 2015 07:30
RSpec - testing callbacks on model spec
class FooModel < ActiveRecord::Base
after_create :after_create_foo
protected
def after_create_foo
foo_method(param1, param2)
end
end