Skip to content

Instantly share code, notes, and snippets.

View niksmac's full-sized avatar
🇮🇳
🧜 Merperson

Nikhil M niksmac

🇮🇳
🧜 Merperson
View GitHub Profile
  1. Describe why it’s hard to code a random number generator in Ethereum. Summarize a few reasons why most intuitive solutions fail (eg. getting from block number)

  2. Describe an efficient approach to using off-chain data in an ethereum contract that minimizes the amount of trust required.

  3. Create an efficient solidity contract that includes the following functions:

  • sqrt(uint x) that returns the square root of a number to 2 decimal places
  • selectionsort(uint[] x) that uses the selection sort algorithm to return a sorted array
  • factorial(int x): returns the factorial of x using recursion
@0x263b
0x263b / colors.md
Last active June 30, 2025 09:26
Random color from string in javascript

Random color from string in javascript

Consider a list of strings you need to permanently assign a random color.

First you should turn the string into a hash.

var string = "string"
var hash = 0
@willm
willm / cmus.md
Last active June 26, 2019 06:21
Cmus cheat sheet

File view 5

a - add file/folder

Library view 2

c - play / pause

v - stop

/**
* Base contract that all upgradeable contracts should use.
*
* Contracts implementing this interface are all called using delegatecall from
* a dispatcher. As a result, the _sizes and _dest variables are shared with the
* dispatcher contract, which allows the called contract to update these at will.
*
* _sizes is a map of function signatures to return value sizes. Due to EVM
* limitations, these need to be populated by the target contract, so the
* dispatcher knows how many bytes of data to return from called functions.
@bensu
bensu / Dropdown.elm
Created August 19, 2015 19:52
Dropdown Component in Elm
module Dropdown where
import List exposing (..)
import Html exposing (..)
import Html.Attributes exposing (style)
import Html.Events exposing (onClick, onBlur)
-- MODEL
@loderunner
loderunner / 01-mac-profiling.md
Last active July 31, 2025 17:31
Profiling an application in Mac OS X

Profiling an application in Mac OS X

Finding which process to profile

If your system is running slowly, perhaps a process is using too much CPU time and won't let other processes run smoothly. To find out which processes are taking up a lot of CPU time, you can use Apple's Activity Monitor.

The CPU pane shows how processes are affecting CPU (processor) activity:

@niksmac
niksmac / drupal-permissionfix.php
Created December 4, 2014 06:01
Automatically Securing file permissions and ownership for Drupal 7
<?php
function SetPerms($dir = ".") {
$listDir = array();
if($handler = opendir($dir)) {
while (($sub = readdir($handler)) !== FALSE) {
if ($sub != "." && $sub != "..") {
if(is_file($dir."/".$sub)) {
echo "File: $dir/$sub\n";
chmod($dir."/".$sub, 0644);
@zhuochun
zhuochun / README.md
Last active June 14, 2023 17:46
List all posts, tags and categories in Jekyll. https://github.com/zhuochun/md-writer

List all posts, tags and categories in Jekyll.

Octopress users: if you found " is escaped in the generated JSON file, please change them to \". Refer to this issue.

@evancz
evancz / Architecture.md
Last active December 21, 2022 14:28
Ideas and guidelines for architecting larger applications in Elm to be modular and extensible

Architecture in Elm

This document is a collection of concepts and strategies to make large Elm projects modular and extensible.

We will start by thinking about the structure of signals in our program. Broadly speaking, your application state should live in one big foldp. You will probably merge a bunch of input signals into a single stream of updates. This sounds a bit crazy at first, but it is in the same ballpark as Om or Facebook's Flux. There are a couple major benefits to having a centralized home for your application state:

  1. There is a single source of truth. Traditional approaches force you to write a decent amount of custom and error prone code to synchronize state between many different stateful components. (The state of this widget needs to be synced with the application state, which needs to be synced with some other widget, etc.) By placing all of your state in one location, you eliminate an entire class of bugs in which two components get into inconsistent states. We also think yo
@umidjons
umidjons / pdf-thumbnail-php.md
Last active December 6, 2023 21:41
Creating PDF thumbnails in PHP

Creating PDF thumbnails in PHP

Install Ghostscript

Download and install right version of ghostscript. In my case my PHP was x86 architecture, so I download Ghostscript 9.14 for Windows (32 bit).

Enable ImageMagick