Skip to content

Instantly share code, notes, and snippets.

View euccas's full-sized avatar

Euccas Chen euccas

View GitHub Profile
@euccas
euccas / create_hash_of_hash.rb
Last active June 8, 2020 00:13
create hash of hash
test_info = Hash.new do |hash, key|
hash[key] = Hash.new
end
@euccas
euccas / quicksort.rb
Last active June 8, 2020 00:14
Here are some things you can do with Gists in GistBox.
# Use Gists to store entire functions
class QuickSort
def self.sort!(keys)
quick(keys,0,keys.size-1)
end
private
def self.quick(keys, left, right)
#!/usr/bin/env ruby
USAGE=<<EOS
Delete files in specified folders that are older than a given number of days.
Options:
-v - verbose. Will list folders and files.
-d - dry run. Like verbose, but does not delete files.
-h - Show this usage help.
Arguments:
@euccas
euccas / divide_group.rb
Last active June 8, 2020 02:00
divide tests into groups
test_num = test_list.length
group_num = test_num / group_length
if test_num % group_length != 0
group_num += 1
end
@euccas
euccas / Jenkinsfile.groovy
Last active June 8, 2020 02:05 — forked from Faheetah/Jenkinsfile.groovy
Jenkinsfile idiosynchrasies with escaping and quotes
node {
echo 'Results included as an inline comment exactly how they are returned as of Jenkins 2.121, with $BUILD_NUMBER = 1'
echo 'No quotes, pipeline command in single quotes'
sh 'echo $BUILD_NUMBER' // 1
echo 'Double quotes are silently dropped'
sh 'echo "$BUILD_NUMBER"' // 1
echo 'Even escaped with a single backslash they are dropped'
sh 'echo \"$BUILD_NUMBER\"' // 1
echo 'Using two backslashes, the quotes are preserved'
sh 'echo \\"$BUILD_NUMBER\\"' // "1"
@euccas
euccas / react_setState.js
Last active June 8, 2020 02:05
react setState
constructor(props) {
super(props)
this.state = {
userName: 'Azat Mardan',
userEmail: 'hi@azat.co',
userId: 3967
}
}
updateValues() {
this.setState({userName: 'Azat'})
import React, { Component } from "react";
import ReactDOM from "react-dom";
class App extends Component {
constructor() {
super();
this.state = { data: [] };
}
componentDidMount() {
fetch(`https://api.coinmarketcap.com/v1/ticker/?limit=10`)
.then(res => res.json())
@euccas
euccas / remove_empty_hash_element.rb
Last active June 8, 2020 02:06
remove empty hash element
def remove_empty_hash_element(h)
if h and h.length>0
h.each do |k,v|
h.delete(k) if v.respond_to?('empty?') and v.empty?
end
end
end
@euccas
euccas / zlib_bi_reverse.cpp
Last active June 8, 2020 02:07
Zlib function: bits reverse
/* ===========================================================================
* Reverse the first len bits of a code, using straightforward code (a faster
* method would use a table)
* IN assertion: 1 <= len <= 15
*/
local unsigned bi_reverse(code, len)
unsigned code; /* the value to invert */
int len; /* its bit length */
{
register unsigned res = 0;
@euccas
euccas / read_mem_to_buffer.cpp
Last active June 8, 2020 02:07
Read memory and store to a 16KB buffer, then output to a file. Pseudo code.
const size_t buffSize = 16 * 1024; // 16KB
size_t currReadSize = buffSize; // default
size_t dumpedSize = 0;
uint8 currBuff[buffSize];
while (currAddr < endAddr)
{
currReadSize = (currAddr + buffSize <= endAddr) ? buffSize : (size_t)(endAddr - currAddr);
read_memory(currBuff, currAddr, sizeof(uint8) * currReadSize, memory_type);
dumpedSize += currReadSize;
currAddr += currReadSize;